Spring: define @RequestMapping value in a properties file(Spring:在属性文件中定义 @RequestMapping 值)
问题描述
是否可以通过在属性文件中定义 @RequestMapping
注释在 Spring 中定义它的值?
Is it possible to define the value of a @RequestMapping
annotation in Spring by defining it in a properties file?
实际上,我会这样做:
@Controller
@RequestMapping("/xxx")
public class MyController {
...
}
但我想将路径 /xxx
存储在属性文件中.为什么?例如,如果我在控制器中重命名路径,我就不太可能在模板中做 mystakes.
But I would like to store the path /xxx
in a properties file. Why? For instance, it is less likely that I do mystakes in my templates if I rename the path in the controller.
在其他框架中这是允许的(例如,参见 Symfony).
In other framework this is allowed (see Symfony, for instance).
推荐答案
应该可以在 @RequestMapping
中使用占位符,例如 @RequestMapping("${foo.bar}")
.看看 文档了解更多详情:
It should be possible to use placeholders in @RequestMapping
, like for example @RequestMapping("${foo.bar}")
. Take a look at the documentation for more details:
@RequestMapping
注释中的模式支持针对本地属性和/或系统属性和环境变量的 ${...
} 占位符.这在控制器映射到的路径可能需要通过配置进行自定义的情况下可能很有用.有关占位符的更多信息,请参阅 PropertyPlaceholderConfigurer 类的 javadocs.
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.
这篇关于Spring:在属性文件中定义 @RequestMapping 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Spring:在属性文件中定义 @RequestMapping 值


基础教程推荐
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 降序排序:Java Map 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01