1 首先在applicationContext.xml中加入:
<beans 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.1.xsd">
</beans> 的命名空间,然后
2
<util:properties id="settings" location="WEB-INF/classes/test.properties" />
注意:这个需要放在<context:component-scan base-package="" />
<context:property-placeholder location="classpath*:application.properties" /> 这种之前,否则会出现莫名错误
3 创建test.properties
<beans 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.1.xsd">
</beans> 的命名空间,然后
2
<util:properties id="settings" location="WEB-INF/classes/test.properties" />
注意:这个需要放在<context:component-scan base-package="" />
<context:property-placeholder location="classpath*:application.properties" /> 这种之前,否则会出现莫名错误
3 创建test.properties
testabc=123
在程序中这样使用
@Value("#{settings.testabc}")
private String abc ;
public String getAbc() {
return abc;
}
public void setAbc(String abc) {
this.abc = abc;
}