java - Spring:在属性文件中定义@RequestMapping值

标签 java spring spring-mvc annotations

是否可以通过在属性文件中定义 Spring 中的 @RequestMapping 注释的值来定义它?

实际上,我做了类似的事情:

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

但我想将路径 /xxx 存储在属性文件中。为什么?例如,如果我重命名 Controller 中的路径,我就不太可能在模板中进行我的操作。

在其他框架中这是允许的(例如,参见 Symfony)。

最佳答案

应该可以在@RequestMapping中使用占位符,例如@RequestMapping("${foo.bar}")。看看documentation了解更多详情:

Patterns in @RequestMapping annotations support ${…​} placeholders against local properties and/or system properties and environment variables. This may be useful in cases where the path a controller is mapped to may need to be customized through configuration. For more information on placeholders, see the javadocs of the PropertyPlaceholderConfigurer class.

关于java - Spring:在属性文件中定义@RequestMapping值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46073581/

相关文章:

java - 在 Spring MVC 中更改过滤器类中的语言环境

java - Android资源未找到异常?

java - 如何使 Tomcat 中的日志轮换工作

java - 从字节数组读取到控制台(或文件)Java

java - Spring - 如何杀死无限循环

java - Spring缓存如何工作?

java - Spring安全注销使 session 范围对象无效,这不是必需的

java - 使用 Spring 计划注释和更新 View

java - 在 Gradle 构建中禁用 findbugs 检查错误类别

java - 找不到 WebApplicationContext : no ContextLoaderListener registered?