java,
分享于 点击 6475 次 点评:201
java,
1 第一种<bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath*:config.properties</value>
</list>
</property>
</bean>
@Value("#{configProperties['ftp_username']}")
private String username;
@Value("#{configProperties['ftp_password']}")
private String password;
@Value("#{configProperties['ftp_ip']}")
private String ip;
@Autowired
Properties configProperties;
2 第二种
<util:properties id="sys" location="classpath:webconfig/sys.properties"/>
@Component
public class SysConf {
@Value("#{sys.test}")
private String test;
@Value("#{sys.test}")
public void setTest(String test){
test = test;
}
@Value("#{sys}")
public void setSysConf(Properties sys){
test= sys.getProperty("test");
}
}
xml加入配置
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<context:component-scan base-package="com.manpedia" >
</context:component-scan>
相关文章
- 暂无相关文章
用户点评