properties work

This commit is contained in:
eugenp
2013-06-01 13:04:45 +03:00
parent a7eeabc8de
commit f5af87c858
3 changed files with 40 additions and 5 deletions
@@ -0,0 +1,30 @@
package org.baeldung.properties.core;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
public class ComponentInXmlUsingProperties implements InitializingBean {
@Autowired
private Environment env;
@Value("${key.something}")
private String injectedProperty;
public ComponentInXmlUsingProperties(final String propertyValue) {
super();
System.out.println("Constructor Injection - Property Value resolted to: " + propertyValue);
}
//
@Override
public void afterPropertiesSet() throws Exception {
System.out.println("in afterPropertiesSet via @Value: " + injectedProperty);
System.out.println("in afterPropertiesSet Environment: " + env.getProperty("key.something"));
}
}
@@ -7,7 +7,7 @@ import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
@Configuration
@ComponentScan("org.baeldung.core")
@ComponentScan("org.baeldung.properties.core")
@PropertySource("classpath:foo.properties")
public class PropertiesWithJavaConfig {
@@ -18,7 +18,7 @@ public class PropertiesWithJavaConfig {
// beans
@Bean
public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}