Search in sources :

Example 11 with RelaxedPropertyResolver

use of org.springframework.boot.bind.RelaxedPropertyResolver in project spring-boot by spring-projects.

the class OnEnabledEndpointCondition method determineEndpointOutcome.

private ConditionOutcome determineEndpointOutcome(String endpointName, boolean enabledByDefault, ConditionContext context) {
    RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(context.getEnvironment(), "endpoints." + endpointName + ".");
    if (resolver.containsProperty("enabled") || !enabledByDefault) {
        boolean match = resolver.getProperty("enabled", Boolean.class, enabledByDefault);
        ConditionMessage message = ConditionMessage.forCondition(ConditionalOnEnabledEndpoint.class, "(" + endpointName + ")").because(match ? "enabled" : "disabled");
        return new ConditionOutcome(match, message);
    }
    return null;
}
Also used : ConditionMessage(org.springframework.boot.autoconfigure.condition.ConditionMessage) RelaxedPropertyResolver(org.springframework.boot.bind.RelaxedPropertyResolver) ConditionOutcome(org.springframework.boot.autoconfigure.condition.ConditionOutcome)

Example 12 with RelaxedPropertyResolver

use of org.springframework.boot.bind.RelaxedPropertyResolver in project spring-boot by spring-projects.

the class OnEnabledEndpointCondition method determineAllEndpointsOutcome.

private ConditionOutcome determineAllEndpointsOutcome(ConditionContext context) {
    RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(context.getEnvironment(), "endpoints.");
    boolean match = Boolean.valueOf(resolver.getProperty("enabled", "true"));
    ConditionMessage message = ConditionMessage.forCondition(ConditionalOnEnabledEndpoint.class).because("All endpoints are " + (match ? "enabled" : "disabled") + " by default");
    return new ConditionOutcome(match, message);
}
Also used : ConditionMessage(org.springframework.boot.autoconfigure.condition.ConditionMessage) RelaxedPropertyResolver(org.springframework.boot.bind.RelaxedPropertyResolver) ConditionOutcome(org.springframework.boot.autoconfigure.condition.ConditionOutcome)

Example 13 with RelaxedPropertyResolver

use of org.springframework.boot.bind.RelaxedPropertyResolver in project spring-boot by spring-projects.

the class CloudFoundryActuatorAutoConfiguration method getCloudFoundrySecurityService.

private CloudFoundrySecurityService getCloudFoundrySecurityService(RestTemplateBuilder restTemplateBuilder, Environment environment) {
    RelaxedPropertyResolver cloudFoundryProperties = new RelaxedPropertyResolver(environment, "management.cloudfoundry.");
    String cloudControllerUrl = environment.getProperty("vcap.application.cf_api");
    boolean skipSslValidation = cloudFoundryProperties.getProperty("skip-ssl-validation", Boolean.class, false);
    return cloudControllerUrl == null ? null : new CloudFoundrySecurityService(restTemplateBuilder, cloudControllerUrl, skipSslValidation);
}
Also used : RelaxedPropertyResolver(org.springframework.boot.bind.RelaxedPropertyResolver)

Example 14 with RelaxedPropertyResolver

use of org.springframework.boot.bind.RelaxedPropertyResolver in project spring-boot by spring-projects.

the class AutoConfigurationImportSelector method getExcludeAutoConfigurationsProperty.

private List<String> getExcludeAutoConfigurationsProperty() {
    if (getEnvironment() instanceof ConfigurableEnvironment) {
        RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(this.environment, "spring.autoconfigure.");
        Map<String, Object> properties = resolver.getSubProperties("exclude");
        if (properties.isEmpty()) {
            return Collections.emptyList();
        }
        List<String> excludes = new ArrayList<>();
        for (Map.Entry<String, Object> entry : properties.entrySet()) {
            String name = entry.getKey();
            Object value = entry.getValue();
            if (name.isEmpty() || name.startsWith("[") && value != null) {
                excludes.addAll(new HashSet<>(Arrays.asList(StringUtils.tokenizeToStringArray(String.valueOf(value), ","))));
            }
        }
        return excludes;
    }
    RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(getEnvironment(), "spring.autoconfigure.");
    String[] exclude = resolver.getProperty("exclude", String[].class);
    return (Arrays.asList(exclude == null ? new String[0] : exclude));
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) RelaxedPropertyResolver(org.springframework.boot.bind.RelaxedPropertyResolver) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 15 with RelaxedPropertyResolver

use of org.springframework.boot.bind.RelaxedPropertyResolver in project spring-boot by spring-projects.

the class CacheCondition method getMatchOutcome.

@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    String sourceClass = "";
    if (metadata instanceof ClassMetadata) {
        sourceClass = ((ClassMetadata) metadata).getClassName();
    }
    ConditionMessage.Builder message = ConditionMessage.forCondition("Cache", sourceClass);
    RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(context.getEnvironment(), "spring.cache.");
    if (!resolver.containsProperty("type")) {
        return ConditionOutcome.match(message.because("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(message.because(value + " cache type"));
    }
    return ConditionOutcome.noMatch(message.because(value + " cache type"));
}
Also used : ClassMetadata(org.springframework.core.type.ClassMetadata) ConditionMessage(org.springframework.boot.autoconfigure.condition.ConditionMessage) RelaxedPropertyResolver(org.springframework.boot.bind.RelaxedPropertyResolver)

Aggregations

RelaxedPropertyResolver (org.springframework.boot.bind.RelaxedPropertyResolver)24 ConditionMessage (org.springframework.boot.autoconfigure.condition.ConditionMessage)5 PropertyResolver (org.springframework.core.env.PropertyResolver)5 ConditionOutcome (org.springframework.boot.autoconfigure.condition.ConditionOutcome)3 Map (java.util.Map)2 MutablePropertySources (org.springframework.core.env.MutablePropertySources)2 PropertySources (org.springframework.core.env.PropertySources)2 PropertySourcesPropertyResolver (org.springframework.core.env.PropertySourcesPropertyResolver)2 AbstractCacheBuilder (com.alicp.jetcache.AbstractCacheBuilder)1 CacheBuilder (com.alicp.jetcache.CacheBuilder)1 ConfigProvider (com.alicp.jetcache.anno.support.ConfigProvider)1 BufferedImage (java.awt.image.BufferedImage)1 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 PostConstruct (javax.annotation.PostConstruct)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 BeansException (org.springframework.beans.BeansException)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1