removed all PropertyPlaceholderConfigure references
This commit is contained in:
parent
29cca467c4
commit
0185b2d0fb
|
@ -1,21 +0,0 @@
|
|||
package com.baeldung.properties.spring;
|
||||
|
||||
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class PropertiesWithPlaceHolderConfigurer {
|
||||
|
||||
public PropertiesWithPlaceHolderConfigurer() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PropertyPlaceholderConfigurer propertyConfigurer() {
|
||||
final PropertyPlaceholderConfigurer props = new PropertyPlaceholderConfigurer();
|
||||
props.setSystemPropertiesMode(PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_FALLBACK);
|
||||
return props;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package com.baeldung.properties.spring;
|
||||
|
||||
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.*;
|
||||
|
||||
@Configuration
|
||||
public class PropertyPlaceholderConfig {
|
||||
|
||||
public PropertyPlaceholderConfig(){
|
||||
super();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public static PropertyPlaceholderConfigurer properties() {
|
||||
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
|
||||
Resource[] resources = new ClassPathResource[]{ new ClassPathResource("foo.properties") };
|
||||
ppc.setLocations( resources );
|
||||
ppc.setIgnoreUnresolvablePlaceholders( true );
|
||||
return ppc;
|
||||
}
|
||||
}
|
|
@ -3,15 +3,6 @@
|
|||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd"
|
||||
>
|
||||
|
||||
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
|
||||
<property name="locations">
|
||||
<list>
|
||||
<value>classpath:foo.properties</value>
|
||||
</list>
|
||||
</property>
|
||||
<property name="ignoreUnresolvablePlaceholders" value="true"/>
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
|
||||
<property name="locations">
|
||||
<list>
|
||||
|
|
|
@ -4,12 +4,11 @@ import org.junit.jupiter.api.Test;
|
|||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
import com.baeldung.properties.spring.PropertyPlaceholderConfig;
|
||||
import com.baeldung.properties.spring.PropertySourcesPlaceholderConfig;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@SpringJUnitConfig({PropertyPlaceholderConfig.class, PropertySourcesPlaceholderConfig.class})
|
||||
@SpringJUnitConfig({PropertySourcesPlaceholderConfig.class})
|
||||
public class MultiplePlaceholdersJavaConfigIntegrationTest {
|
||||
|
||||
@Value("${key.something}")
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
package com.baeldung.properties.parentchild;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.ContextHierarchy;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import com.baeldung.properties.parentchild.config.ChildConfig2;
|
||||
import com.baeldung.properties.parentchild.config.ParentConfig2;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@WebAppConfiguration
|
||||
@ContextHierarchy({ @ContextConfiguration(classes = ParentConfig2.class), @ContextConfiguration(classes = ChildConfig2.class) })
|
||||
public class ParentChildPropertyPlaceHolderPropertiesIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private WebApplicationContext wac;
|
||||
|
||||
@Test
|
||||
public void givenPropertyPlaceHolder_whenGetPropertyUsingEnv_thenCorrect() {
|
||||
final Environment childEnv = wac.getEnvironment();
|
||||
final Environment parentEnv = wac.getParent().getEnvironment();
|
||||
|
||||
assertNull(parentEnv.getProperty("parent.name"));
|
||||
assertNull(parentEnv.getProperty("child.name"));
|
||||
|
||||
assertNull(childEnv.getProperty("parent.name"));
|
||||
assertNull(childEnv.getProperty("child.name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenPropertyPlaceHolder_whenGetPropertyUsingValueAnnotation_thenCorrect() {
|
||||
final ChildValueHolder childValueHolder = wac.getBean(ChildValueHolder.class);
|
||||
final ParentValueHolder parentValueHolder = wac.getParent().getBean(ParentValueHolder.class);
|
||||
|
||||
assertEquals(parentValueHolder.getParentName(), "parent");
|
||||
assertEquals(parentValueHolder.getChildName(), "-");
|
||||
|
||||
assertEquals(childValueHolder.getParentName(), "-");
|
||||
assertEquals(childValueHolder.getChildName(), "child");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package com.baeldung.properties.parentchild.config;
|
||||
|
||||
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
import com.baeldung.properties.parentchild.ChildValueHolder;
|
||||
|
||||
@Configuration
|
||||
public class ChildConfig2 {
|
||||
|
||||
@Bean
|
||||
public ChildValueHolder childValueHolder() {
|
||||
return new ChildValueHolder();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public static PropertyPlaceholderConfigurer properties() {
|
||||
final PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
|
||||
ppc.setLocations(new ClassPathResource("child.properties"));
|
||||
return ppc;
|
||||
}
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package com.baeldung.properties.parentchild.config;
|
||||
|
||||
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
import com.baeldung.properties.parentchild.ParentValueHolder;
|
||||
|
||||
@Configuration
|
||||
public class ParentConfig2 {
|
||||
|
||||
@Bean
|
||||
public ParentValueHolder parentValueHolder() {
|
||||
return new ParentValueHolder();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public static PropertyPlaceholderConfigurer properties() {
|
||||
final PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
|
||||
ppc.setLocations(new ClassPathResource("parent.properties"));
|
||||
return ppc;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue