1. 程式人生 > >spring mvc controller中獲取屬性檔案(properties)的值

spring mvc controller中獲取屬性檔案(properties)的值

1.將properties檔案位置加到spring mvc的配置的檔案(spring-mvc.xml)中,如下

<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
        <property name="fileEncoding" value="UTF-8" />  
        <property name="location" value="classpath:conf/http.properties"
/> </bean>

2.http.properties配置檔案

http.url=192.168.1.10  
http.port=8086  

3.Controller程式碼

@Value("${http.url}")  
private String strUrl;  

@Value("${http.port}")  
private String strPort;