properties work
This commit is contained in:
+30
@@ -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"));
|
||||
}
|
||||
|
||||
}
|
||||
+2
-2
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user