spring mvc 怎么读取properties文件
1个回答
展开全部
(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");
望采纳~
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");
望采纳~
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询