Patterns in @RequestMapping annotations support ${...} placeholders which can be substituted with local properties and/or system properties and environment variables. Following example shows how to achieve that.
Example
The Controller
@Controller
public class MyController {
@RequestMapping("/${app.path}")
@ResponseBody
public String handleTestRequest () {
return "test output";
}
}
src/main/resources/my-props.properties
app.path = test/test2
JavaConfig class
@EnableWebMvc
@ComponentScan("com.logicbig.example")
@PropertySource("classpath:my-props.properties")
public class AppConfig {
}
WebApplicationInitializer implementation
public class WebAppInitializer extends
AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses () {
return new Class<?>[]{AppConfig.class};
}
@Override
protected Class<?>[] getServletConfigClasses () {
return null;
}
@Override
protected String[] getServletMappings () {
return new String[]{"/"};
}
}