當前位置: 首頁>>代碼示例>>Java>>正文


Java ActiveProfiles類代碼示例

本文整理匯總了Java中org.springframework.test.context.ActiveProfiles的典型用法代碼示例。如果您正苦於以下問題:Java ActiveProfiles類的具體用法?Java ActiveProfiles怎麽用?Java ActiveProfiles使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ActiveProfiles類屬於org.springframework.test.context包,在下文中一共展示了ActiveProfiles類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: resolve

import org.springframework.test.context.ActiveProfiles; //導入依賴的package包/類
/**
 * Resolve the <em>bean definition profiles</em> for the given {@linkplain
 * Class test class} based on profiles configured declaratively via
 * {@link ActiveProfiles#profiles} or {@link ActiveProfiles#value}.
 * @param testClass the test class for which the profiles should be resolved;
 * never {@code null}
 * @return the list of bean definition profiles to use when loading the
 * {@code ApplicationContext}; never {@code null}
 */
@Override
public String[] resolve(Class<?> testClass) {
	Assert.notNull(testClass, "Class must not be null");

	final Set<String> activeProfiles = new LinkedHashSet<String>();

	Class<ActiveProfiles> annotationType = ActiveProfiles.class;
	AnnotationDescriptor<ActiveProfiles> descriptor = findAnnotationDescriptor(testClass, annotationType);

	if (descriptor == null) {
		if (logger.isDebugEnabled()) {
			logger.debug(String.format(
				"Could not find an 'annotation declaring class' for annotation type [%s] and class [%s]",
				annotationType.getName(), testClass.getName()));
		}
	}
	else {
		Class<?> declaringClass = descriptor.getDeclaringClass();
		ActiveProfiles annotation = descriptor.synthesizeAnnotation();

		if (logger.isTraceEnabled()) {
			logger.trace(String.format("Retrieved @ActiveProfiles [%s] for declaring class [%s].", annotation,
				declaringClass.getName()));
		}

		for (String profile : annotation.profiles()) {
			if (StringUtils.hasText(profile)) {
				activeProfiles.add(profile.trim());
			}
		}
	}

	return StringUtils.toStringArray(activeProfiles);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:44,代碼來源:DefaultActiveProfilesResolver.java


注:本文中的org.springframework.test.context.ActiveProfiles類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。