removed all PropertyPlaceholderConfigure references

This commit is contained in:
Gerardo Roza 2020-11-23 12:30:41 -03:00
parent 29cca467c4
commit 0185b2d0fb
7 changed files with 1 additions and 154 deletions

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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>

View File

@ -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}")

View File

@ -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");
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}