1、配置文件目录结构:
dev为开发环境配置,其中和sit有差别的配置文件是application.properties,jdbc.properties,redis.properties、以及需要维护两份spring配置文件。
2、spring配置分离(如果spring-context.xml有更新,需要维护两份 - -!)
dev环境下spring-spring-context.xml配置读取classpath下的资源文件
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<array>
<value>classpath:application.properties</value>
<value>classpath:jdbc.properties</value>
<value>classpath:redis.properties</value>
</array>
</property>
</bean>
SIT 环境下spring-
spring-context.xml配置读取sit服务器上的资源文件
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<array>
<value>file:/bqhexin/conf/rcbms/application.properties</value>
<value>file:/bqhexin/conf/rcbms/jdbc.properties</value>
<value>file:/bqhexin/conf/rcbms/redis.properties</value>
</array>
</property>
</bean>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:META-INF/spring/spring-context.xml,
classpath:META-INF/mybatis/spring-mybatis.xml
</param-value>
</context-param>
3、maven配置
profiles配置:
<profiles>
<profile>
<!-- 本地开发环境 -->
<id>dev</id>
<properties>
<package.environment>dev</package.environment>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<!-- 测试环境 -->
<id>sit</id>
<properties>
<package.environment>sit</package.environment>
</properties>
</profile>
</profiles>
build:
<build>
<finalName>rcbms</finalName>
<!--<sourceDirectory>src</sourceDirectory>-->
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<webXml>src\main\webapp\WEB-INF\web.xml</webXml>
<!--<warSourceDirectory>WebRoot</warSourceDirectory>-->
<!--<archive>-->
<!--<addMavenDescriptor>false</addMavenDescriptor>-->
<!--</archive>-->
<!--<warName>Cms</warName>-->
<webResources>
<resource>
<directory>src/main/resources/${package.environment}/</directory>
<targetPath>WEB-INF/classes</targetPath>
<filtering>true</filtering>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src</directory>
<filtering>true</filtering>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
</build>
<directory>src/main/resources/${package.environment}/</directory>不能写成绝对路径<directory>/src/main/resources/${package.environment}/</directory>,Linux系统下找不到的。
4、打包测试
在项目根目录下打开DOS窗口使用打包命令mvn clean package -P sit或者mvn clean package -P dev,就可以打出不同配置的包