一个系统中通常会存在如下一些以Properties形式存在的配置文件
1.数据库配置文件demo-db.properties:
2.消息服务配置文件demo-mq.properties:
3.远程调用的配置文件demo-remote.properties:
一、系统中需要加载多个Properties配置文件
应用场景:Properties配置文件不止一个,需要在系统启动时同时加载多个Properties文件。
配置方式:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://.demo.remote.Client"> <property name="properties" ref="remoteConfigs" /> </bean> </beans>代码如下:
import org.springframework.beans.factory.annotation.Autowired; public class Client() { //@Autowired也可以使用 private Properties remoteSettings; //getter setter }五、使用通配符加载多个properties文件
<context:property-placeholder location="file:///${CONFIG_PATH}/*.properties" />或者
上述的各个场景在项目群中特别有用,需要灵活的使用上述各种配置方式。以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。