在RequestMapping值中使用属性

时间:2016-01-31 02:18:40

标签: spring properties controller

我想使用属性文件(资源文件夹中的文件)内的值来定义RequestMapping。

@RequestMapping(value = "X", produces = "application/json")
public String hello() {

}

我怎样才能阅读" X"从属性文件?

编辑:我尝试使用@PropertySource注释,但它并没有在" X"

中工作

编辑2:我也试试这个,但是它起作用但不适用于@RequestMapping(值=" X")

@Bean
public static PropertySourcesPlaceholderConfigurer placeHolderConfigurer() {
    PropertySourcesPlaceholderConfigurer propertyConfigurer = new PropertySourcesPlaceholderConfigurer();
    propertyConfigurer.setLocations(new PathMatchingResourcePatternResolver().getResources("classpath:/**/abc.properties"));
    return propertyConfigurer;
}

由于

1 个答案:

答案 0 :(得分:2)

应该可以在@RequestMapping中使用占位符。阅读documentation了解更多详情

@RequestMapping("${foo.bar}", produces = "application/json")
public String hello() {
    ....
}
相关问题