配置文件中
<bean id="address" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<array>
<value>classpath:address.properties</value>
</array>
</property>
</bean>
address.properties
ip=127.0.0.1
port=9999
contorller中
String ip;
int port;
@Value("#{address.ip}")
public void setIp(String ip) {
System.out.println(ip);
this.ip = ip;
}
@Value("#{address.port}")
public void setPort(String port) {
System.out.println(port);
this.port = Integer.parseInt(port);
}
然后就可以在方法中调用啦
启动项目出现
[INFO] [2016-11-03 10:42:16][org.springframework.beans.factory.config.PropertiesFactoryBean(172)]Loading properties file from class path resource [address.properties]
127.0.0.1
9999