/** * Create a ClassPathScanningCandidateComponentProvider with a {@link StandardEnvironment}. * @param useDefaultFilters whether to register the default filters for the * {@link Component @Component}, {@link Repository @Repository}, * {@link Service @Service}, and {@link Controller @Controller} * stereotype annotations * @see #registerDefaultFilters() */ public ClassPathScanningCandidateComponentProvider(boolean useDefaultFilters) { this(useDefaultFilters, new StandardEnvironment()); }
@Override public boolean containsProperty(String name) { for (PropertySource<?> propertySource : this.propertySources) { if (propertySource.containsProperty(name)) { return true; } } return false; }
@Override public String resolvePlaceholders(String text) { if (this.nonStrictHelper == null) { this.nonStrictHelper = createPlaceholderHelper(true); } return doResolvePlaceholders(text, this.nonStrictHelper); }
/** * Create a new {@code MutablePropertySources} from the given propertySources * object, preserving the original order of contained {@code PropertySource} objects. */ public MutablePropertySources(PropertySources propertySources) { this(); for (PropertySource<?> propertySource : propertySources) { addLast(propertySource); } }
/** * Return whether this {@code PropertySource} contains the given name. * <p>This implementation simply checks for a {@code null} return value * from {@link #getProperty(String)}. Subclasses may wish to implement * a more efficient algorithm if possible. * @param name the property name to find */ public boolean containsProperty(String name) { return (getProperty(name) != null); }
/** * Customize the set of {@link PropertySources} to be used by this configurer. * <p>Setting this property indicates that environment property sources and * local properties should be ignored. * @see #postProcessBeanFactory */ public void setPropertySources(PropertySources propertySources) { this.propertySources = new MutablePropertySources(propertySources); }
/** * Add the given property source object with precedence immediately higher * than the named relative property source. */ public void addBefore(String relativePropertySourceName, PropertySource<?> propertySource) { assertLegalRelativeAddition(relativePropertySourceName, propertySource); removeIfPresent(propertySource); int index = assertPresentAndGetIndex(relativePropertySourceName); addAtIndex(index, propertySource); }
/** * Create a new {@code SimpleCommandLinePropertySource} having the given name * and backed by the given {@code String[]} of command line arguments. */ public SimpleCommandLinePropertySource(String name, String[] args) { super(name, new SimpleCommandLineArgsParser().parse(args)); }
/** * Return {@code true} if a property with the given name or any underscore/uppercase variant * thereof exists in this property source. */ @Override public boolean containsProperty(String name) { return (getProperty(name) != null); }
@Override public boolean matches(Predicate<String> activeProfiles) { for (Profiles candidate : this.parsed) { if (candidate.matches(activeProfiles)) { return true; } } return false; }
@Override public String getProperty(String key, String defaultValue) { String value = getProperty(key); return (value != null ? value : defaultValue); }
/** * Create a new {@code Environment} instance, calling back to * {@link #customizePropertySources(MutablePropertySources)} during construction to * allow subclasses to contribute or manipulate {@link PropertySource} instances as * appropriate. * @see #customizePropertySources(MutablePropertySources) */ public AbstractEnvironment() { customizePropertySources(this.propertySources); }
@Override public String getMessage() { return "The following properties were declared as required but could not be resolved: " + getMissingRequiredProperties(); }
/** * Return a new {@link StandardEnvironment}. * <p>Subclasses may override this method in order to supply * a custom {@link ConfigurableEnvironment} implementation. */ protected ConfigurableEnvironment createEnvironment() { return new StandardEnvironment(); }
/** * Add the given property source object with precedence immediately lower * than the named relative property source. */ public void addAfter(String relativePropertySourceName, PropertySource<?> propertySource) { assertLegalRelativeAddition(relativePropertySourceName, propertySource); removeIfPresent(propertySource); int index = assertPresentAndGetIndex(relativePropertySourceName); addAtIndex(index + 1, propertySource); }
@Override public boolean containsProperty(String key) { if (this.propertySources != null) { for (PropertySource<?> propertySource : this.propertySources) { if (propertySource.containsProperty(key)) { return true; } } } return false; }
/** * Create a new {@code SimpleCommandLinePropertySource} having the default name * and backed by the given {@code String[]} of command line arguments. * @see CommandLinePropertySource#COMMAND_LINE_PROPERTY_SOURCE_NAME * @see CommandLinePropertySource#CommandLinePropertySource(Object) */ public SimpleCommandLinePropertySource(String... args) { super(new SimpleCommandLineArgsParser().parse(args)); }
@Override public String resolveRequiredPlaceholders(String text) throws IllegalArgumentException { if (this.strictHelper == null) { this.strictHelper = createPlaceholderHelper(false); } return doResolvePlaceholders(text, this.strictHelper); }
@Override public <T> T getProperty(String key, Class<T> targetType, T defaultValue) { T value = getProperty(key, targetType); return (value != null ? value : defaultValue); }
@Override public final Environment getEnvironment() { if (this.environment == null) { this.environment = new StandardEnvironment(); } return this.environment; }