做项目难免会用到自定义配置文件,其实很easy,做个学习笔记吧!
configure.properties 文件
configure.imagepath=/Users/john/Desktop
Configure.java
public class Configure {
private String imagePath;
public String getImagePath() {
return imagePath;
}
public void setImagePath(String imagePath) {
this.imagePath = imagePath;
}
}
spring.xml 文件,当项目存在多个 properties 文件时必须加上 ignore-unresolvable="true"
<!-- 加载外部配置变量 -->
<context:property-placeholder location="classpath:configure.properties"
ignore-unresolvable="true" />
<bean id="configure" class="com.nbgt.cls.base.Configure">
<property name="imagePath" value="${configure.imagepath}"></property>
</bean>