properties work
This commit is contained in:
parent
a7eeabc8de
commit
f5af87c858
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -6,8 +6,13 @@
|
|||
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">
|
||||
|
||||
<util:properties id="fooProperties" location="classpath:foo.properties" />
|
||||
<context:property-placeholder properties-ref="fooProperties" />
|
||||
<!-- <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" />
|
||||
|
||||
<bean id="componentInXmlUsingProperties" class="org.baeldung.properties.core.ComponentInXmlUsingProperties" >
|
||||
<constructor-arg value="${key.something}" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
Loading…
Reference in New Issue