properties logic moved entirelly under a package
This commit is contained in:
		
							parent
							
								
									52995a5194
								
							
						
					
					
						commit
						a7eeabc8de
					
				| @ -1,4 +1,4 @@ | ||||
| package org.baeldung.core; | ||||
| package org.baeldung.properties.core; | ||||
| 
 | ||||
| import org.springframework.beans.factory.InitializingBean; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| @ -23,8 +23,8 @@ public class ComponentUsingProperties implements InitializingBean { | ||||
| 
 | ||||
|     @Override | ||||
|     public void afterPropertiesSet() throws Exception { | ||||
|         System.out.println("via @Value: " + injectedProperty); | ||||
|         System.out.println("via Environment: " + env.getProperty("key.something")); | ||||
|         System.out.println("in afterPropertiesSet via @Value: " + injectedProperty); | ||||
|         System.out.println("in afterPropertiesSet Environment: " + env.getProperty("key.something")); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| @ -0,0 +1,25 @@ | ||||
| package org.baeldung.properties.spring; | ||||
| 
 | ||||
| import org.springframework.context.annotation.Bean; | ||||
| import org.springframework.context.annotation.ComponentScan; | ||||
| import org.springframework.context.annotation.Configuration; | ||||
| import org.springframework.context.annotation.PropertySource; | ||||
| import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; | ||||
| 
 | ||||
| @Configuration | ||||
| @ComponentScan("org.baeldung.core") | ||||
| @PropertySource("classpath:foo.properties") | ||||
| public class PropertiesWithJavaConfig { | ||||
| 
 | ||||
|     public PropertiesWithJavaConfig() { | ||||
|         super(); | ||||
|     } | ||||
| 
 | ||||
|     // beans | ||||
| 
 | ||||
|     @Bean | ||||
|     public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { | ||||
|         return new PropertySourcesPlaceholderConfigurer(); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| @ -1,14 +1,13 @@ | ||||
| package org.baeldung.spring.properties; | ||||
| package org.baeldung.properties.spring; | ||||
| 
 | ||||
| import org.springframework.context.annotation.ComponentScan; | ||||
| import org.springframework.context.annotation.Configuration; | ||||
| import org.springframework.context.annotation.ImportResource; | ||||
| import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; | ||||
| 
 | ||||
| @Configuration | ||||
| @ImportResource("classpath:configForProperties.xml") | ||||
| @ComponentScan("org.baeldung.core") | ||||
| public class PropertiesWithXmlConfig extends WebMvcConfigurerAdapter { | ||||
| public class PropertiesWithXmlConfig { | ||||
| 
 | ||||
|     public PropertiesWithXmlConfig() { | ||||
|         super(); | ||||
| @ -1,17 +0,0 @@ | ||||
| package org.baeldung.spring.properties; | ||||
| 
 | ||||
| import org.springframework.context.annotation.ComponentScan; | ||||
| import org.springframework.context.annotation.Configuration; | ||||
| import org.springframework.context.annotation.PropertySource; | ||||
| import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; | ||||
| 
 | ||||
| @Configuration | ||||
| @ComponentScan("org.baeldung.core") | ||||
| @PropertySource("classpath:foo.properties") | ||||
| public class PropertiesWithJavaConfig extends WebMvcConfigurerAdapter { | ||||
| 
 | ||||
|     public PropertiesWithJavaConfig() { | ||||
|         super(); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| @ -1,9 +1,13 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" | ||||
|     xmlns:util="http://www.springframework.org/schema/util" | ||||
|     xsi:schemaLocation=" | ||||
|       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd | ||||
|       http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd | ||||
|       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd"> | ||||
| 
 | ||||
|     <context:property-placeholder location="classpath:foo.properties" /> | ||||
|     <util:properties id="fooProperties" location="classpath:foo.properties" /> | ||||
|     <context:property-placeholder properties-ref="fooProperties" /> | ||||
|     <!-- <context:property-placeholder location="classpath:foo.properties" /> --> | ||||
| 
 | ||||
| </beans> | ||||
| @ -12,6 +12,8 @@ | ||||
| 
 | ||||
| 	<!-- in order to debug some marshalling issues, this needs to be TRACE --> | ||||
| 	<logger name="org.springframework.web.servlet.mvc" level="WARN" /> | ||||
|      | ||||
|     <logger name="org.springframework.core.io.support" level="INFO" /> | ||||
| 
 | ||||
| 	<root level="INFO"> | ||||
| 		<appender-ref ref="STDOUT" /> | ||||
|  | ||||
| @ -1,8 +1,11 @@ | ||||
| package org.baeldung.core; | ||||
| package org.baeldung.properties.core; | ||||
| 
 | ||||
| import org.baeldung.spring.properties.PropertiesWithJavaConfig; | ||||
| import org.baeldung.properties.spring.PropertiesWithJavaConfig; | ||||
| import org.junit.Test; | ||||
| import org.junit.runner.RunWith; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.beans.factory.annotation.Value; | ||||
| import org.springframework.core.env.Environment; | ||||
| import org.springframework.test.context.ContextConfiguration; | ||||
| import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||||
| import org.springframework.test.context.support.AnnotationConfigContextLoader; | ||||
| @ -11,9 +14,16 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader; | ||||
| @ContextConfiguration(classes = { PropertiesWithJavaConfig.class }, loader = AnnotationConfigContextLoader.class) | ||||
| public class PropertiesWithJavaIntegrationTest { | ||||
| 
 | ||||
|     @Autowired | ||||
|     private Environment env; | ||||
| 
 | ||||
|     @Value("${key.something}") | ||||
|     private String injectedProperty; | ||||
| 
 | ||||
|     @Test | ||||
|     public final void givenContextIsInitialized_thenNoException() { | ||||
|         // | ||||
|         System.out.println("in test via @Value: " + injectedProperty); | ||||
|         System.out.println("in test Environment: " + env.getProperty("key.something")); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| @ -1,8 +1,11 @@ | ||||
| package org.baeldung.core; | ||||
| package org.baeldung.properties.core; | ||||
| 
 | ||||
| import org.baeldung.spring.properties.PropertiesWithXmlConfig; | ||||
| import org.baeldung.properties.spring.PropertiesWithXmlConfig; | ||||
| import org.junit.Test; | ||||
| import org.junit.runner.RunWith; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.beans.factory.annotation.Value; | ||||
| import org.springframework.core.env.Environment; | ||||
| import org.springframework.test.context.ContextConfiguration; | ||||
| import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||||
| import org.springframework.test.context.support.AnnotationConfigContextLoader; | ||||
| @ -11,9 +14,16 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader; | ||||
| @ContextConfiguration(classes = { PropertiesWithXmlConfig.class }, loader = AnnotationConfigContextLoader.class) | ||||
| public class PropertiesWithXmlIntegrationTest { | ||||
| 
 | ||||
|     @Autowired | ||||
|     private Environment env; | ||||
| 
 | ||||
|     @Value("${key.something}") | ||||
|     private String injectedProperty; | ||||
| 
 | ||||
|     @Test | ||||
|     public final void givenContextIsInitialized_thenNoException() { | ||||
|         // | ||||
|         System.out.println("in test via @Value: " + injectedProperty); | ||||
|         System.out.println("in test Environment: " + env.getProperty("key.something")); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user