@RequestMapping with placeholder not working

后端 未结 1 1526
不知归路
不知归路 2020-12-20 05:30

So i have spend hours to try to get the anwser of this post working:
Overriding RequestMapping on SpringMVC controller

But it really is not working. What I have

相关标签:
1条回答
  • 2020-12-20 06:37

    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)
    
    0 讨论(0)
提交回复
热议问题