做项目难免会用到自定义配置文件,其实很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>
本文介绍了如何在项目中使用自定义配置文件,并通过配置解析来整合不同来源的配置信息。重点阐述了配置文件的结构、配置类的设计以及Spring框架中的配置加载与整合机制。
2287

被折叠的 条评论
为什么被折叠?



