springmvc如何通过properties读取配置文件

论坛 期权论坛 编程之家     
选择匿名的用户   2021-5-23 11:12   11   0

(1)在spring-mvc.xml加入:

xmlns:util="http://www.springframework.org/schema/util"

http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd


<!-- 方式2:加载配置文件 -->
<util:properties id="applicationProps" location="classpath:conf/config_development.properties"/>

(2)在controller中加入:

@Autowired
private Properties applicationProps;


public Properties getApplicationProps() {
return applicationProps;
}


public void setApplicationProps(Properties applicationProps) {
this.applicationProps = applicationProps;
}

(3).在controller中利用applicationProps读取配置文件

String jumpUrl = applicationProps.getProperty("learn.jump.url");

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP