Java war包配置分离

来源:互联网 发布:软件工程学的内容 编辑:程序博客网 时间:2024/06/08 17:18

1、引入properties文件时使用外部目录下的properties文件,文件存放在服务器



2、读取配置文件会先执行propertyConfigurer1,当找不到propertyConfigurer1对应的文件时会读取propertyConfigurer2下的本地文件,本地开发避免启动报错

<bean id="propertyConfigurer1" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><property name="order" value="1"/>          <property name="ignoreResourceNotFound" value="true"/>          <property name="ignoreUnresolvablePlaceholders" value="true" /> <property name="locations"><array><value>classpath:application.properties</value><!-- 读取服务器地址 --><value>file:/bqhexin/conf/rcbms/jdbc.properties</value><value>file:/bqhexin/conf/rcbms/redis.properties</value> </array></property></bean><bean id="propertyConfigurer2" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><property name="order" value="2"/>          <property name="ignoreUnresolvablePlaceholders" value="true" /><property name="locations"><array><value>classpath:application.properties</value><value>classpath:jdbc.properties</value><value>classpath:redis.properties</value></array></property></bean>
3、打成war包后,删除classpath下的properties文件,这样就只能读取服务器目录下资源文件,便于在SIT或者生产启动时发现问题