I have several @RequestMapping which value will subject to change from \"/XXX\" to \"/V100\" on someday. So I need to define it in properties. I\'ve googled and the
In addition to the xml solution provided by @JustinB, here is an annotation-only solution (tested with Spring Boot):
@Controller
@PropertySource(value = "classpath:/user.properties", ignoreResourceNotFound = true)
@RequestMapping("/${api.version:}")
public class MyController {
...
}
The value of api.version is read from If src/main/resources/user.properties if it exists. If the file is missing or api.version is not set, it will default to an empty string.
Beware, if api.version is also defined in application.properties it will take precedence whether or not user.properties exists and api.version is set in it.
More examples of @PropertySource are provided here.