Spring: define @RequestMapping value in properties file

Is it possible to determine the value of the @RequestMapping annotation in Spring by defining it in the properties file?

Actually, I am doing something like:

 @Controller @RequestMapping("/xxx") public class MyController { ... } 

But I would like to save the path /xxx in the properties file. What for? For example, it is less likely that I make puzzles in my templates if I rename the path in the controller.

In other frameworks, this is allowed (see, for example, Symfony).

+7
java spring spring-mvc annotations
source share
1 answer

It should be possible to use placeholders in @RequestMapping , for example, @RequestMapping("${foo.bar}") . More information can be found in the documentation :

The templates in @RequestMapping annotations support ${…​ placeholders from local properties and / or system properties and environment variables. This can be useful in cases where the path to which the controller is mapped may need to be configured through the configuration. For more information about placeholders, see Javadocs of the PropertyPlaceholderConfigurer class.

+14
source share

All Articles