Java Code Examples for org.springframework.core.env.PropertySource.StubPropertySource

The following examples show how to use org.springframework.core.env.PropertySource.StubPropertySource. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private boolean isIgnored(PropertySource<?> candidate) {
    return (candidate instanceof StubPropertySource
            || candidate instanceof ConfigurationPropertySourcesPropertySource);
}
 
Example 2
private static boolean isIncluded(PropertySource<?> source) {
    return !(source instanceof StubPropertySource)
            && !(source instanceof ConfigurationPropertySourcesPropertySource);
}
 
Example 3
/**
 * Replace {@code Servlet}-based {@link StubPropertySource stub property sources} with
 * actual instances populated with the given {@code servletContext} and
 * {@code servletConfig} objects.
 * <p>This method is idempotent with respect to the fact it may be called any number
 * of times but will perform replacement of stub property sources with their
 * corresponding actual property sources once and only once.
 * @param propertySources the {@link MutablePropertySources} to initialize (must not
 * be {@code null})
 * @param servletContext the current {@link ServletContext} (ignored if {@code null}
 * or if the {@link StandardServletEnvironment#SERVLET_CONTEXT_PROPERTY_SOURCE_NAME
 * servlet context property source} has already been initialized)
 * @param servletConfig the current {@link ServletConfig} (ignored if {@code null}
 * or if the {@link StandardServletEnvironment#SERVLET_CONFIG_PROPERTY_SOURCE_NAME
 * servlet config property source} has already been initialized)
 * @see org.springframework.core.env.PropertySource.StubPropertySource
 * @see org.springframework.core.env.ConfigurableEnvironment#getPropertySources()
 */
public static void initServletPropertySources(
		MutablePropertySources propertySources, ServletContext servletContext, ServletConfig servletConfig) {

	Assert.notNull(propertySources, "'propertySources' must not be null");
	if (servletContext != null && propertySources.contains(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME) &&
			propertySources.get(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME) instanceof StubPropertySource) {
		propertySources.replace(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME,
				new ServletContextPropertySource(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME, servletContext));
	}
	if (servletConfig != null && propertySources.contains(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME) &&
			propertySources.get(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME) instanceof StubPropertySource) {
		propertySources.replace(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME,
				new ServletConfigPropertySource(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME, servletConfig));
	}
}
 
Example 4
/**
 * Replace {@code Servlet}-based {@link StubPropertySource stub property sources} with
 * actual instances populated with the given {@code servletContext} and
 * {@code servletConfig} objects.
 * <p>This method is idempotent with respect to the fact it may be called any number
 * of times but will perform replacement of stub property sources with their
 * corresponding actual property sources once and only once.
 * @param propertySources the {@link MutablePropertySources} to initialize (must not
 * be {@code null})
 * @param servletContext the current {@link ServletContext} (ignored if {@code null}
 * or if the {@link StandardServletEnvironment#SERVLET_CONTEXT_PROPERTY_SOURCE_NAME
 * servlet context property source} has already been initialized)
 * @param servletConfig the current {@link ServletConfig} (ignored if {@code null}
 * or if the {@link StandardServletEnvironment#SERVLET_CONFIG_PROPERTY_SOURCE_NAME
 * servlet config property source} has already been initialized)
 * @see org.springframework.core.env.PropertySource.StubPropertySource
 * @see org.springframework.core.env.ConfigurableEnvironment#getPropertySources()
 */
public static void initServletPropertySources(
		MutablePropertySources propertySources, ServletContext servletContext, ServletConfig servletConfig) {

	Assert.notNull(propertySources, "propertySources must not be null");
	if (servletContext != null && propertySources.contains(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME) &&
			propertySources.get(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME) instanceof StubPropertySource) {
		propertySources.replace(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME,
				new ServletContextPropertySource(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME, servletContext));
	}
	if (servletConfig != null && propertySources.contains(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME) &&
			propertySources.get(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME) instanceof StubPropertySource) {
		propertySources.replace(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME,
				new ServletConfigPropertySource(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME, servletConfig));
	}
}
 
Example 5
Source Project: spring-analysis-note   Source File: StandardServletEnvironment.java    License: MIT License 3 votes vote down vote up
/**
 * Customize the set of property sources with those contributed by superclasses as
 * well as those appropriate for standard servlet-based environments:
 * <ul>
 * <li>{@value #SERVLET_CONFIG_PROPERTY_SOURCE_NAME}
 * <li>{@value #SERVLET_CONTEXT_PROPERTY_SOURCE_NAME}
 * <li>{@value #JNDI_PROPERTY_SOURCE_NAME}
 * </ul>
 * <p>Properties present in {@value #SERVLET_CONFIG_PROPERTY_SOURCE_NAME} will
 * take precedence over those in {@value #SERVLET_CONTEXT_PROPERTY_SOURCE_NAME}, and
 * properties found in either of the above take precedence over those found in
 * {@value #JNDI_PROPERTY_SOURCE_NAME}.
 * <p>Properties in any of the above will take precedence over system properties and
 * environment variables contributed by the {@link StandardEnvironment} superclass.
 * <p>The {@code Servlet}-related property sources are added as
 * {@link StubPropertySource stubs} at this stage, and will be
 * {@linkplain #initPropertySources(ServletContext, ServletConfig) fully initialized}
 * once the actual {@link ServletContext} object becomes available.
 * @see StandardEnvironment#customizePropertySources
 * @see org.springframework.core.env.AbstractEnvironment#customizePropertySources
 * @see ServletConfigPropertySource
 * @see ServletContextPropertySource
 * @see org.springframework.jndi.JndiPropertySource
 * @see org.springframework.context.support.AbstractApplicationContext#initPropertySources
 * @see #initPropertySources(ServletContext, ServletConfig)
 */
@Override
protected void customizePropertySources(MutablePropertySources propertySources) {
	propertySources.addLast(new StubPropertySource(SERVLET_CONFIG_PROPERTY_SOURCE_NAME));
	propertySources.addLast(new StubPropertySource(SERVLET_CONTEXT_PROPERTY_SOURCE_NAME));
	if (JndiLocatorDelegate.isDefaultJndiEnvironmentAvailable()) {
		propertySources.addLast(new JndiPropertySource(JNDI_PROPERTY_SOURCE_NAME));
	}
	super.customizePropertySources(propertySources);
}
 
Example 6
Source Project: spring-analysis-note   Source File: WebApplicationContextUtils.java    License: MIT License 3 votes vote down vote up
/**
 * Replace {@code Servlet}-based {@link StubPropertySource stub property sources} with
 * actual instances populated with the given {@code servletContext} and
 * {@code servletConfig} objects.
 * <p>This method is idempotent with respect to the fact it may be called any number
 * of times but will perform replacement of stub property sources with their
 * corresponding actual property sources once and only once.
 * @param sources the {@link MutablePropertySources} to initialize (must not
 * be {@code null})
 * @param servletContext the current {@link ServletContext} (ignored if {@code null}
 * or if the {@link StandardServletEnvironment#SERVLET_CONTEXT_PROPERTY_SOURCE_NAME
 * servlet context property source} has already been initialized)
 * @param servletConfig the current {@link ServletConfig} (ignored if {@code null}
 * or if the {@link StandardServletEnvironment#SERVLET_CONFIG_PROPERTY_SOURCE_NAME
 * servlet config property source} has already been initialized)
 * @see org.springframework.core.env.PropertySource.StubPropertySource
 * @see org.springframework.core.env.ConfigurableEnvironment#getPropertySources()
 */
public static void initServletPropertySources(MutablePropertySources sources,
		@Nullable ServletContext servletContext, @Nullable ServletConfig servletConfig) {

	Assert.notNull(sources, "'propertySources' must not be null");
	String name = StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME;
	if (servletContext != null && sources.contains(name) && sources.get(name) instanceof StubPropertySource) {
		sources.replace(name, new ServletContextPropertySource(name, servletContext));
	}
	name = StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME;
	if (servletConfig != null && sources.contains(name) && sources.get(name) instanceof StubPropertySource) {
		sources.replace(name, new ServletConfigPropertySource(name, servletConfig));
	}
}
 
Example 7
Source Project: java-technology-stack   Source File: StandardServletEnvironment.java    License: MIT License 3 votes vote down vote up
/**
 * Customize the set of property sources with those contributed by superclasses as
 * well as those appropriate for standard servlet-based environments:
 * <ul>
 * <li>{@value #SERVLET_CONFIG_PROPERTY_SOURCE_NAME}
 * <li>{@value #SERVLET_CONTEXT_PROPERTY_SOURCE_NAME}
 * <li>{@value #JNDI_PROPERTY_SOURCE_NAME}
 * </ul>
 * <p>Properties present in {@value #SERVLET_CONFIG_PROPERTY_SOURCE_NAME} will
 * take precedence over those in {@value #SERVLET_CONTEXT_PROPERTY_SOURCE_NAME}, and
 * properties found in either of the above take precedence over those found in
 * {@value #JNDI_PROPERTY_SOURCE_NAME}.
 * <p>Properties in any of the above will take precedence over system properties and
 * environment variables contributed by the {@link StandardEnvironment} superclass.
 * <p>The {@code Servlet}-related property sources are added as
 * {@link StubPropertySource stubs} at this stage, and will be
 * {@linkplain #initPropertySources(ServletContext, ServletConfig) fully initialized}
 * once the actual {@link ServletContext} object becomes available.
 * @see StandardEnvironment#customizePropertySources
 * @see org.springframework.core.env.AbstractEnvironment#customizePropertySources
 * @see ServletConfigPropertySource
 * @see ServletContextPropertySource
 * @see org.springframework.jndi.JndiPropertySource
 * @see org.springframework.context.support.AbstractApplicationContext#initPropertySources
 * @see #initPropertySources(ServletContext, ServletConfig)
 */
@Override
protected void customizePropertySources(MutablePropertySources propertySources) {
	propertySources.addLast(new StubPropertySource(SERVLET_CONFIG_PROPERTY_SOURCE_NAME));
	propertySources.addLast(new StubPropertySource(SERVLET_CONTEXT_PROPERTY_SOURCE_NAME));
	if (JndiLocatorDelegate.isDefaultJndiEnvironmentAvailable()) {
		propertySources.addLast(new JndiPropertySource(JNDI_PROPERTY_SOURCE_NAME));
	}
	super.customizePropertySources(propertySources);
}
 
Example 8
Source Project: java-technology-stack   Source File: WebApplicationContextUtils.java    License: MIT License 3 votes vote down vote up
/**
 * Replace {@code Servlet}-based {@link StubPropertySource stub property sources} with
 * actual instances populated with the given {@code servletContext} and
 * {@code servletConfig} objects.
 * <p>This method is idempotent with respect to the fact it may be called any number
 * of times but will perform replacement of stub property sources with their
 * corresponding actual property sources once and only once.
 * @param sources the {@link MutablePropertySources} to initialize (must not
 * be {@code null})
 * @param servletContext the current {@link ServletContext} (ignored if {@code null}
 * or if the {@link StandardServletEnvironment#SERVLET_CONTEXT_PROPERTY_SOURCE_NAME
 * servlet context property source} has already been initialized)
 * @param servletConfig the current {@link ServletConfig} (ignored if {@code null}
 * or if the {@link StandardServletEnvironment#SERVLET_CONFIG_PROPERTY_SOURCE_NAME
 * servlet config property source} has already been initialized)
 * @see org.springframework.core.env.PropertySource.StubPropertySource
 * @see org.springframework.core.env.ConfigurableEnvironment#getPropertySources()
 */
public static void initServletPropertySources(MutablePropertySources sources,
		@Nullable ServletContext servletContext, @Nullable ServletConfig servletConfig) {

	Assert.notNull(sources, "'propertySources' must not be null");
	String name = StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME;
	if (servletContext != null && sources.contains(name) && sources.get(name) instanceof StubPropertySource) {
		sources.replace(name, new ServletContextPropertySource(name, servletContext));
	}
	name = StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME;
	if (servletConfig != null && sources.contains(name) && sources.get(name) instanceof StubPropertySource) {
		sources.replace(name, new ServletConfigPropertySource(name, servletConfig));
	}
}
 
Example 9
/**
 * Customize the set of property sources with those contributed by superclasses as
 * well as those appropriate for standard servlet-based environments:
 * <ul>
 * <li>{@value #SERVLET_CONFIG_PROPERTY_SOURCE_NAME}
 * <li>{@value #SERVLET_CONTEXT_PROPERTY_SOURCE_NAME}
 * <li>{@value #JNDI_PROPERTY_SOURCE_NAME}
 * </ul>
 * <p>Properties present in {@value #SERVLET_CONFIG_PROPERTY_SOURCE_NAME} will
 * take precedence over those in {@value #SERVLET_CONTEXT_PROPERTY_SOURCE_NAME}, and
 * properties found in either of the above take precedence over those found in
 * {@value #JNDI_PROPERTY_SOURCE_NAME}.
 * <p>Properties in any of the above will take precedence over system properties and
 * environment variables contributed by the {@link StandardEnvironment} superclass.
 * <p>The {@code Servlet}-related property sources are added as
 * {@link StubPropertySource stubs} at this stage, and will be
 * {@linkplain #initPropertySources(ServletContext, ServletConfig) fully initialized}
 * once the actual {@link ServletContext} object becomes available.
 * @see StandardEnvironment#customizePropertySources
 * @see org.springframework.core.env.AbstractEnvironment#customizePropertySources
 * @see ServletConfigPropertySource
 * @see ServletContextPropertySource
 * @see org.springframework.jndi.JndiPropertySource
 * @see org.springframework.context.support.AbstractApplicationContext#initPropertySources
 * @see #initPropertySources(ServletContext, ServletConfig)
 */
@Override
protected void customizePropertySources(MutablePropertySources propertySources) {
	propertySources.addLast(new StubPropertySource(SERVLET_CONFIG_PROPERTY_SOURCE_NAME));
	propertySources.addLast(new StubPropertySource(SERVLET_CONTEXT_PROPERTY_SOURCE_NAME));
	if (JndiLocatorDelegate.isDefaultJndiEnvironmentAvailable()) {
		propertySources.addLast(new JndiPropertySource(JNDI_PROPERTY_SOURCE_NAME));
	}
	super.customizePropertySources(propertySources);
}
 
Example 10
/**
 * Customize the set of property sources with those contributed by superclasses as
 * well as those appropriate for standard portlet-based environments:
 * <ul>
 * <li>{@value #PORTLET_CONFIG_PROPERTY_SOURCE_NAME}
 * <li>{@value #PORTLET_CONTEXT_PROPERTY_SOURCE_NAME}
 * <li>{@linkplain StandardServletEnvironment#SERVLET_CONTEXT_PROPERTY_SOURCE_NAME "servletContextInitParams"}
 * <li>{@linkplain StandardServletEnvironment#JNDI_PROPERTY_SOURCE_NAME "jndiProperties"}
 * </ul>
 * <p>Properties present in {@value #PORTLET_CONFIG_PROPERTY_SOURCE_NAME} will
 * take precedence over those in {@value #PORTLET_CONTEXT_PROPERTY_SOURCE_NAME},
 * which takes precedence over those in {@linkplain
 * StandardServletEnvironment#SERVLET_CONTEXT_PROPERTY_SOURCE_NAME "servletContextInitParams"}
 * and so on.
 * <p>Properties in any of the above will take precedence over system properties and
 * environment variables contributed by the {@link StandardEnvironment} superclass.
 * <p>The property sources are added as stubs for now, and will be
 * {@linkplain PortletApplicationContextUtils#initPortletPropertySources fully
 * initialized} once the actual {@link PortletConfig}, {@link PortletContext}, and
 * {@link ServletContext} objects are available.
 * @see StandardEnvironment#customizePropertySources
 * @see org.springframework.core.env.AbstractEnvironment#customizePropertySources
 * @see PortletConfigPropertySource
 * @see PortletContextPropertySource
 * @see PortletApplicationContextUtils#initPortletPropertySources
 */
@Override
protected void customizePropertySources(MutablePropertySources propertySources) {
	propertySources.addLast(new StubPropertySource(PORTLET_CONFIG_PROPERTY_SOURCE_NAME));
	propertySources.addLast(new StubPropertySource(PORTLET_CONTEXT_PROPERTY_SOURCE_NAME));
	propertySources.addLast(new StubPropertySource(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME));
	if (JndiLocatorDelegate.isDefaultJndiEnvironmentAvailable()) {
		propertySources.addLast(new JndiPropertySource(StandardServletEnvironment.JNDI_PROPERTY_SOURCE_NAME));
	}
	super.customizePropertySources(propertySources);
}
 
Example 11
/**
 * Customize the set of property sources with those contributed by superclasses as
 * well as those appropriate for standard servlet-based environments:
 * <ul>
 * <li>{@value #SERVLET_CONFIG_PROPERTY_SOURCE_NAME}
 * <li>{@value #SERVLET_CONTEXT_PROPERTY_SOURCE_NAME}
 * <li>{@value #JNDI_PROPERTY_SOURCE_NAME}
 * </ul>
 * <p>Properties present in {@value #SERVLET_CONFIG_PROPERTY_SOURCE_NAME} will
 * take precedence over those in {@value #SERVLET_CONTEXT_PROPERTY_SOURCE_NAME}, and
 * properties found in either of the above take precedence over those found in
 * {@value #JNDI_PROPERTY_SOURCE_NAME}.
 * <p>Properties in any of the above will take precedence over system properties and
 * environment variables contributed by the {@link StandardEnvironment} superclass.
 * <p>The {@code Servlet}-related property sources are added as
 * {@link StubPropertySource stubs} at this stage, and will be
 * {@linkplain #initPropertySources(ServletContext, ServletConfig) fully initialized}
 * once the actual {@link ServletContext} object becomes available.
 * @see StandardEnvironment#customizePropertySources
 * @see org.springframework.core.env.AbstractEnvironment#customizePropertySources
 * @see ServletConfigPropertySource
 * @see ServletContextPropertySource
 * @see org.springframework.jndi.JndiPropertySource
 * @see org.springframework.context.support.AbstractApplicationContext#initPropertySources
 * @see #initPropertySources(ServletContext, ServletConfig)
 */
@Override
protected void customizePropertySources(MutablePropertySources propertySources) {
	propertySources.addLast(new StubPropertySource(SERVLET_CONFIG_PROPERTY_SOURCE_NAME));
	propertySources.addLast(new StubPropertySource(SERVLET_CONTEXT_PROPERTY_SOURCE_NAME));
	if (JndiLocatorDelegate.isDefaultJndiEnvironmentAvailable()) {
		propertySources.addLast(new JndiPropertySource(JNDI_PROPERTY_SOURCE_NAME));
	}
	super.customizePropertySources(propertySources);
}