trying to wrap my brain around Spring 3.1's Environment + Profiles + PropertySource concepts and don't quite understand why declaring a context:property-placeholder does NOT automatically register underlying PropertySource with ctx's Environment?
Doing this in xml config:
allows, among other things, to resolve @Value-annotated bean props, for example in a spring bean class:Code:<context:property-placeholder location="classpath:myapp.properties"/>
...yet, inside the same bean, the following will not return trueCode:@Value("${myprop1}") //assume declared in myapp.properties private String prop1Value; @Autowired private ConfigurableApplicationContext ctx;
which seems inconsistent v. @Value eval.Code:ctx.getEnvironment().containsProperty("myprop1"); //returns false
..unless I write another bean that, at container startup will do something like:
Code:PropertiesPropertySource ps = new PropertiesPropertySource("myapp_props", myappProps); ctx.getEnvironment().getPropertySources().addFirst(ps);
Why wouldn't the last step be done automatically by the framework as result of context:property-placeholder declaration?
just trying to understand the rationale...


Reply With Quote
