1. 程式人生 > >springmvc如何通過properties讀取配置檔案

springmvc如何通過properties讀取配置檔案

(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");