将其添加到您的上下文中
<context:property-placeholder location="${envfile}"/>
Run Code Online (Sandbox Code Playgroud)
这将加载位于$ {envfile}的属性文件,这是一个可以用Java的启动参数设置的变量,如下所示
-Denvfile="file:/var/server/environment.properties"
Run Code Online (Sandbox Code Playgroud)
或者也许在Tomcat的启动脚本中
CATALINA_OPTS=" -Denvfile=file:/var/server/environment.properties"
Run Code Online (Sandbox Code Playgroud)
可以使用Springs Value注释在控制器中检索值,如下所示:
@Values("${myvalue}")
private String myValue;
Run Code Online (Sandbox Code Playgroud)
请注意,这些功能需要Spring 3.1,更多信息请点击此处
祝好运!
| 归档时间: |
|
| 查看次数: |
5248 次 |
| 最近记录: |