I had this problem also and solved it once I realized that a PropertyPlaceholderConfigurer
bean wasn't loaded into the context of the module where many of the placeholders existed.
Simple solution was to refactor our externalized configuration. In the end, I moved the @PropertySources
definition and PropertyPlaceholderConfigurer
bean to a common module and all is well:
@Configuration
@PropertySources(value = {@PropertySource("classpath:app-config.properties")})
public class ExternalizedConfig {
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
The request mappings like this work as expected now:
@RequestMapping(value="/${foo.bar.rest_proxy_uri}/**", method = RequestMethod.GET)
In fact, on server startup, you will see the placeholders have been resolved:
2015-05-06 16:21:52 INFO RequestMappingHandlerMapping:220 - Mapped "{[/restProxy/**],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<java.lang.String> foo.bar.web.controllers.RestfulFooBarProxyController.proxyGet(javax.servlet.http.HttpServletRequest)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…