use of org.springframework.jndi.JndiPropertySource in project spring-framework by spring-projects.
the class StandardServletEnvironment method customizePropertySources.
/**
* 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 (jndiPresent && JndiLocatorDelegate.isDefaultJndiEnvironmentAvailable()) {
propertySources.addLast(new JndiPropertySource(JNDI_PROPERTY_SOURCE_NAME));
}
super.customizePropertySources(propertySources);
}
use of org.springframework.jndi.JndiPropertySource in project waltz by khartec.
the class DIConfiguration method propertySourcesPlaceholderConfigurer.
/* Required for property interpolation to work correctly */
/**
* @see <a href="http://stackoverflow.com/a/41760877/2311919">Explanation</a>
*/
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer(ConfigurableEnvironment env) {
PropertySourcesPlaceholderConfigurer placeholderConfigurer = new PropertySourcesPlaceholderConfigurer();
JndiPropertySource jndiPropertySource = new JndiPropertySource("java:comp");
env.getPropertySources().addFirst(jndiPropertySource);
return placeholderConfigurer;
}
use of org.springframework.jndi.JndiPropertySource in project java-chassis by ServiceComb.
the class TestConfigurationSpringInitializer method testSetEnvironment.
@Test
public void testSetEnvironment() {
ConfigurableEnvironment environment = Mockito.mock(ConfigurableEnvironment.class);
MutablePropertySources propertySources = new MutablePropertySources();
Map<String, String> propertyMap = new HashMap<>();
final String map0Key0 = "map0-Key0";
final String map1Key0 = "map1-Key0";
final String map2Key0 = "map2-Key0";
final String map3Key0 = "map3-Key0";
propertyMap.put(map0Key0, "map0-Value0");
propertyMap.put(map1Key0, "map1-Value0");
propertyMap.put(map2Key0, "map2-Value0");
propertyMap.put(map3Key0, "map3-Value0");
/*
propertySources
|- compositePropertySource0
| |- mapPropertySource0
| | |- map0-Key0 = map0-Value0
| |- compositePropertySource1
| |- mapPropertySource1
| | |- map1-Key0 = map1-Value0
| |- mapPropertySource2
| |- map2-Key0 = map2-Value0
| |- JndiPropertySource(mocked)
|- mapPropertySource3
|- map3-Key0 = map3-Value0
*/
CompositePropertySource compositePropertySource0 = new CompositePropertySource("compositePropertySource0");
propertySources.addFirst(compositePropertySource0);
HashMap<String, Object> map0 = new HashMap<>();
map0.put(map0Key0, propertyMap.get(map0Key0));
MapPropertySource mapPropertySource0 = new MapPropertySource("mapPropertySource0", map0);
compositePropertySource0.addFirstPropertySource(mapPropertySource0);
CompositePropertySource compositePropertySource1 = new CompositePropertySource("compositePropertySource1");
compositePropertySource0.addPropertySource(compositePropertySource1);
HashMap<String, Object> map1 = new HashMap<>();
map1.put(map1Key0, propertyMap.get(map1Key0));
MapPropertySource mapPropertySource1 = new MapPropertySource("mapPropertySource1", map1);
compositePropertySource1.addPropertySource(mapPropertySource1);
HashMap<String, Object> map2 = new HashMap<>();
map2.put(map2Key0, propertyMap.get(map2Key0));
MapPropertySource mapPropertySource2 = new MapPropertySource("mapPropertySource2", map2);
compositePropertySource1.addPropertySource(mapPropertySource2);
compositePropertySource1.addPropertySource(Mockito.mock(JndiPropertySource.class));
HashMap<String, Object> map3 = new HashMap<>();
map3.put(map3Key0, propertyMap.get(map3Key0));
MapPropertySource mapPropertySource3 = new MapPropertySource("mapPropertySource3", map3);
compositePropertySource0.addPropertySource(mapPropertySource3);
Mockito.when(environment.getPropertySources()).thenReturn(propertySources);
Mockito.doAnswer((Answer<String>) invocation -> {
Object[] args = invocation.getArguments();
String propertyName = (String) args[0];
if ("spring.config.name".equals(propertyName) || "spring.application.name".equals(propertyName)) {
return null;
}
String value = propertyMap.get(propertyName);
if (null == value) {
fail("get unexpected property name: " + propertyName);
}
return value;
}).when(environment).getProperty(anyString(), Matchers.eq(Object.class));
new ConfigurationSpringInitializer().setEnvironment(environment);
Map<String, Map<String, Object>> extraLocalConfig = getExtraConfigMapFromConfigUtil();
assertFalse(extraLocalConfig.isEmpty());
Map<String, Object> extraProperties = extraLocalConfig.get(ConfigurationSpringInitializer.EXTRA_CONFIG_SOURCE_PREFIX + environment.getClass().getName() + "@" + environment.hashCode());
assertNotNull(extraLocalConfig);
for (Entry<String, String> entry : propertyMap.entrySet()) {
assertEquals(entry.getValue(), extraProperties.get(entry.getKey()));
}
}
use of org.springframework.jndi.JndiPropertySource in project waltz by khartec.
the class DIConfiguration method propertySourcesPlaceholderConfigurer.
/**
* Required for property interpolation to work correctly
* @see <a href="http://stackoverflow.com/a/41760877/2311919">Explanation</a>
*/
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer(ConfigurableEnvironment env) {
PropertySourcesPlaceholderConfigurer placeholderConfigurer = new PropertySourcesPlaceholderConfigurer();
JndiPropertySource jndiPropertySource = new JndiPropertySource("java:comp");
env.getPropertySources().addFirst(jndiPropertySource);
return placeholderConfigurer;
}
Aggregations