本文整理匯總了Java中org.springframework.context.annotation.ConditionContext類的典型用法代碼示例。如果您正苦於以下問題:Java ConditionContext類的具體用法?Java ConditionContext怎麽用?Java ConditionContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ConditionContext類屬於org.springframework.context.annotation包,在下文中一共展示了ConditionContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getMatchOutcome
import org.springframework.context.annotation.ConditionContext; //導入依賴的package包/類
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) {
ConfigurableEnvironment environment = (ConfigurableEnvironment) context
.getEnvironment();
ResourceProperties properties = new ResourceProperties();
RelaxedDataBinder binder = new RelaxedDataBinder(properties, "spring.resources");
binder.bind(new PropertySourcesPropertyValues(environment.getPropertySources()));
Boolean match = properties.getChain().getEnabled();
if (match == null) {
boolean webJarsLocatorPresent = ClassUtils.isPresent(WEBJAR_ASSERT_LOCATOR,
getClass().getClassLoader());
return new ConditionOutcome(webJarsLocatorPresent,
"Webjars locator (" + WEBJAR_ASSERT_LOCATOR + ") is "
+ (webJarsLocatorPresent ? "present" : "absent"));
}
return new ConditionOutcome(match,
"Resource chain is " + (match ? "enabled" : "disabled"));
}
示例2: getMatchOutcome
import org.springframework.context.annotation.ConditionContext; //導入依賴的package包/類
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) {
ConditionMessage.Builder message = ConditionMessage
.forCondition("OAuth JWT Condition");
Environment environment = context.getEnvironment();
String keyValue = environment
.getProperty("security.oauth2.resource.jwt.key-value");
String keyUri = environment
.getProperty("security.oauth2.resource.jwt.key-uri");
if (StringUtils.hasText(keyValue) || StringUtils.hasText(keyUri)) {
return ConditionOutcome
.match(message.foundExactly("provided public key"));
}
return ConditionOutcome
.noMatch(message.didNotFind("provided public key").atAll());
}
開發者ID:spring-projects,項目名稱:spring-security-oauth2-boot,代碼行數:18,代碼來源:ResourceServerTokenServicesConfiguration.java
示例3: getMatchOutcome
import org.springframework.context.annotation.ConditionContext; //導入依賴的package包/類
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) {
String[] enablers = context.getBeanFactory()
.getBeanNamesForAnnotation(EnableOAuth2Sso.class);
ConditionMessage.Builder message = ConditionMessage
.forCondition("@EnableOAuth2Sso Condition");
for (String name : enablers) {
if (context.getBeanFactory().isTypeMatch(name,
WebSecurityConfigurerAdapter.class)) {
return ConditionOutcome.match(message
.found("@EnableOAuth2Sso annotation on WebSecurityConfigurerAdapter")
.items(name));
}
}
return ConditionOutcome.noMatch(message.didNotFind(
"@EnableOAuth2Sso annotation " + "on any WebSecurityConfigurerAdapter")
.atAll());
}
示例4: getMatchOutcome
import org.springframework.context.annotation.ConditionContext; //導入依賴的package包/類
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) {
CloudFactory cloudFactory = new CloudFactory();
try {
Cloud cloud = cloudFactory.getCloud();
List<ServiceInfo> serviceInfos = cloud.getServiceInfos();
for (ServiceInfo serviceInfo : serviceInfos) {
if (serviceInfo instanceof VaultServiceInfo) {
return ConditionOutcome.match(String.format(
"Found Vault service %s", serviceInfo.getId()));
}
}
return ConditionOutcome.noMatch("No Vault service found");
}
catch (CloudException e) {
return ConditionOutcome.noMatch("Not running in a Cloud");
}
}
開發者ID:pivotal-cf,項目名稱:spring-cloud-vault-connector,代碼行數:23,代碼來源:VaultConnectorBootstrapConfiguration.java
示例5: BeanSearchSpec
import org.springframework.context.annotation.ConditionContext; //導入依賴的package包/類
BeanSearchSpec(ConditionContext context, AnnotatedTypeMetadata metadata, Class<?> annotationType) {
this.annotationType = annotationType;
MultiValueMap<String, Object> attributes = metadata.getAllAnnotationAttributes(annotationType.getName(), true);
collect(attributes, "name", this.names);
collect(attributes, "value", this.types);
collect(attributes, "type", this.types);
collect(attributes, "annotation", this.annotations);
collect(attributes, "ignored", this.ignoredTypes);
collect(attributes, "ignoredType", this.ignoredTypes);
this.strategy = (SearchStrategy) metadata.getAnnotationAttributes(annotationType.getName()).get("search");
BeanTypeDeductionException deductionException = null;
try {
if (this.types.isEmpty() && this.names.isEmpty()) {
addDeducedBeanType(context, metadata, this.types);
}
} catch (BeanTypeDeductionException ex) {
deductionException = ex;
}
validate(deductionException);
}
示例6: getMatchOutcome
import org.springframework.context.annotation.ConditionContext; //導入依賴的package包/類
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
final RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(context.getEnvironment(),
"holon.swagger.");
if (!resolver.getProperty("holon.swagger.enabled", boolean.class, true)) {
return ConditionOutcome.noMatch(ConditionMessage.forCondition("SwaggerApiAutoDetectCondition")
.because("holon.swagger.enabled is false"));
}
if (resolver.containsProperty("resourcePackage")) {
return ConditionOutcome.noMatch(
ConditionMessage.forCondition("SwaggerApiAutoDetectCondition").available("resourcePackage"));
}
Map<String, Object> ag = resolver.getSubProperties("apiGroups");
if (ag != null && ag.size() > 0) {
return ConditionOutcome
.noMatch(ConditionMessage.forCondition("SwaggerApiAutoDetectCondition").available("apiGroups"));
}
return ConditionOutcome.match();
}
示例7: getMatchOutcome
import org.springframework.context.annotation.ConditionContext; //導入依賴的package包/類
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) {
ConditionMessage.Builder message = ConditionMessage
.forCondition("EmbeddedDataSource");
if (anyMatches(context, metadata, this.pooledCondition)) {
return ConditionOutcome
.noMatch(message.foundExactly("supported pooled data source"));
}
EmbeddedDatabaseType type = EmbeddedDatabaseConnection
.get(context.getClassLoader()).getType();
if (type == null) {
return ConditionOutcome
.noMatch(message.didNotFind("embedded database").atAll());
}
return ConditionOutcome.match(message.found("embedded database").items(type));
}
示例8: getMatchOutcome
import org.springframework.context.annotation.ConditionContext; //導入依賴的package包/類
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
Map<String, Object> attributes = metadata.getAnnotationAttributes(ConditionalOnPropertyPrefix.class.getName());
if (attributes.containsKey("value")) {
String prefix = (String) attributes.get("value");
if (prefix != null && !prefix.trim().equals("")) {
final String propertyPrefix = !prefix.endsWith(".") ? prefix + "." : prefix;
ConfigPropertyProvider configPropertyProvider = EnvironmentConfigPropertyProvider
.create(context.getEnvironment());
Set<String> names = configPropertyProvider.getPropertyNames()
.filter((n) -> n.startsWith(propertyPrefix)).collect(Collectors.toSet());
if (!names.isEmpty()) {
return ConditionOutcome.match();
}
return ConditionOutcome.noMatch(
ConditionMessage.forCondition(ConditionalOnPropertyPrefix.class).notAvailable(propertyPrefix));
}
}
return ConditionOutcome.match();
}
示例9: getMatchOutcome
import org.springframework.context.annotation.ConditionContext; //導入依賴的package包/類
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) {
String prefix = (String) attribute(metadata, "prefix");
Class<?> value = (Class<?>) attribute(metadata, "value");
ConfigurableEnvironment environment = (ConfigurableEnvironment) context.getEnvironment();
try {
new Binder(ConfigurationPropertySources.from(environment.getPropertySources()))
.bind(prefix, Bindable.of(value))
.orElseThrow(
() -> new FatalBeanException("Could not bind DataSourceSettings properties"));
return new ConditionOutcome(true, String.format("Map property [%s] is not empty", prefix));
} catch (Exception e) {
//ignore
}
return new ConditionOutcome(false, String.format("Map property [%s] is empty", prefix));
}
示例10: isSpringSecurityEnabled
import org.springframework.context.annotation.ConditionContext; //導入依賴的package包/類
private boolean isSpringSecurityEnabled(ConditionContext ctx) {
boolean enabled = true;
Environment env = ctx.getEnvironment();
for (String propName : props) {
if (env.containsProperty(propName)) {
if (!Boolean.parseBoolean(env.getProperty(propName))) {
enabled = false;
break;
}
}
}
if (enabled) {
enabled = ClassUtils.isPresent(SPRING_SEC_CLASS_NAME, ctx.getClassLoader());
}
return enabled;
}
示例11: isWebApplication
import org.springframework.context.annotation.ConditionContext; //導入依賴的package包/類
private ConditionOutcome isWebApplication(ConditionContext context,
AnnotatedTypeMetadata metadata) {
if (!ClassUtils.isPresent(WEB_CONTEXT_CLASS, context.getClassLoader())) {
return ConditionOutcome.noMatch("web application classes not found");
}
if (context.getBeanFactory() != null) {
String[] scopes = context.getBeanFactory().getRegisteredScopeNames();
if (ObjectUtils.containsElement(scopes, "session")) {
return ConditionOutcome.match("found web application 'session' scope");
}
}
if (context.getEnvironment() instanceof StandardServletEnvironment) {
return ConditionOutcome
.match("found web application StandardServletEnvironment");
}
if (context.getResourceLoader() instanceof WebApplicationContext) {
return ConditionOutcome.match("found web application WebApplicationContext");
}
return ConditionOutcome.noMatch("not a web application");
}
示例12: getMatchOutcome
import org.springframework.context.annotation.ConditionContext; //導入依賴的package包/類
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) {
boolean webApplicationRequired = metadata
.isAnnotated(ConditionalOnWebApplication.class.getName());
ConditionOutcome webApplication = isWebApplication(context, metadata);
if (webApplicationRequired && !webApplication.isMatch()) {
return ConditionOutcome.noMatch(webApplication.getMessage());
}
if (!webApplicationRequired && webApplication.isMatch()) {
return ConditionOutcome.noMatch(webApplication.getMessage());
}
return ConditionOutcome.match(webApplication.getMessage());
}
示例13: getMatchOutcome
import org.springframework.context.annotation.ConditionContext; //導入依賴的package包/類
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
if (!metadata.isAnnotated(ConditionalOnDevelopment.class.getName())) {
return ConditionOutcome.match(StringUtils.EMPTY);
}
Boolean isDevMode = Env.getBoolean("application.devMode", null);
if (null == isDevMode) {
isDevMode = Env.getBoolean("application.dev-mode", null);
}
isDevMode = null == isDevMode ? false : isDevMode;
if (!isDevMode) {
return ConditionOutcome.noMatch("this is not dev-mode!");
}
return ConditionOutcome.match("this is dev-mode!");
}
示例14: BeanSearchSpec
import org.springframework.context.annotation.ConditionContext; //導入依賴的package包/類
BeanSearchSpec(ConditionContext context, AnnotatedTypeMetadata metadata,
Class<?> annotationType) {
this.annotationType = annotationType;
MultiValueMap<String, Object> attributes = metadata
.getAllAnnotationAttributes(annotationType.getName(), true);
collect(attributes, "name", this.names);
collect(attributes, "value", this.types);
collect(attributes, "type", this.types);
collect(attributes, "annotation", this.annotations);
collect(attributes, "ignored", this.ignoredTypes);
collect(attributes, "ignoredType", this.ignoredTypes);
this.strategy = (SearchStrategy) metadata
.getAnnotationAttributes(annotationType.getName()).get("search");
BeanTypeDeductionException deductionException = null;
try {
if (this.types.isEmpty() && this.names.isEmpty()) {
addDeducedBeanType(context, metadata, this.types);
}
}
catch (BeanTypeDeductionException ex) {
deductionException = ex;
}
validate(deductionException);
}
示例15: getMatchOutcome
import org.springframework.context.annotation.ConditionContext; //導入依賴的package包/類
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) {
RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(
context.getEnvironment(), "spring.cache.");
if (!resolver.containsProperty("type")) {
return ConditionOutcome.match("Automatic cache type");
}
CacheType cacheType = CacheConfigurations
.getType(((AnnotationMetadata) metadata).getClassName());
String value = resolver.getProperty("type").replace("-", "_").toUpperCase();
if (value.equals(cacheType.name())) {
return ConditionOutcome.match("Cache type " + cacheType);
}
return ConditionOutcome.noMatch("Cache type " + value);
}