in sit environment testing, because the server environment and the local environment may be different, can cause a lot of problems, so it will be packaged multiple times. And the configuration file is different, so each package will have to modify the configuration file, very cumbersome.
maven Packaging can be a profile reference to the external, so you can drop the SIT environment configuration to the server, and then each package dynamically select the configuration file reference address, it is very cool.
1.maven,pom configuration, for example:
<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > < Modelversion>4.0.0</modelversion> <parent> <artifactId>666</artifactId> ;groupid>com.xxx</groupid> <version>0.1.0</version> </parent> <artifactid> ;xxx</artifactid> <packaging>war</packaging> <name>xxx</name> <DESCRIPTION&G
t;xxxxxx</description> <build> <finalName>xxx</finalName> <resources> <resource> <directory>src/main/java</directory> <INCLUDES&G
T
<include>**/*.properties</include> <include>**/*.xml</include>
</includes> <filtering>true</filtering> </resource> <resource> <directory>src/main/resources</directory> <includes> <include&
Gt;**</include> </includes> <filtering>true</filtering>
</resource> </resources> </build> <dependencies> <dependency> <groupId>ojdbc</groupId> <artifactId>ojdbc</artifactId> <versi on>12.1.0.1-atlassian-hosted</version> </dependency> </dependencies> <properties&
Gt <file.config.path-sit> This is the sit configuration path, such as:/project-sit/config/xxx/</file.config.path-sit> < File.config.path-prod> here is the production configuration path, such as:/project-prod/config/xxx/</file.config.path-prod> </properties
> <profiles><!--development environment--> <profile> <id>dev</id> <activation>
<activeByDefault>true</activeByDefault> </activation> <properties> <some.config.path> classpath:config/some.properties <jdbc.conf Ig.path> classpath:config/jdbc.properties </jdbc.config.path> ;/properties> </profile> <!--sit test environment--> <profile> <id>si t</id> <properties> <some.config.path> File:${file.confi
G.path-sit}some.properties </some.config.path> <jdbc.config.path> File:${file.config.path-sit}jdbc.properties </jdbc.config.path> </properties > </profile> <!--generation environment--> <profile> <id>prod</id> <properties
> <some.config.path> file:${file.config.path-prod}some.properties </some.config.path> <jdbc.config.path> File:${file.config.path-prod}j Dbc.properties </jdbc.config.path> </properties> </profile> ;/profiles> </project>
2. Referencing the configuration file's XML configuration, for example:
<?xml version= "1.0" encoding= "UTF-8"?> <beans xmlns=
"Http://www.springframework.org/schema/beans"
xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xmlns:context= "Http://www.springframework.org/schema /context "xsi:schemalocation=" Http://www.springframework.org/schema/beans http://www.springframework.org/schema/ Beans/spring-beans.xsd Http://www.springframework.org/schema/context
http://www.springframework.org/schema/ Context/spring-context.xsd ">
<!--Introducing Property Profiles-->
<bean class=" com.xxx.xxx.xxx.xxx ">
< Property Name= "Locations" >
<list>
<value>${some.config.path}</value>
<value >${jdbc.config.path}</value>
</list>
</property>
</bean>
</ Beans>
3. At the time of packing. Using Maven for install, the commands are as follows:
MVN package-p sit
Sit is the configuration path to the SIT environment (if you pack it in Eclipse, remove the MVN command header), and if you use this Package command, the XML reference configuration file path in the war package that you typed is changed, as follows:
<?xml version= "1.0" encoding= "UTF-8"?> "<beans xmlns=" http:// Www.springframework.org/schema/beans "xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance "xmlns:context=" http ://www.springframework.org/schema/context "xsi:schemalocation=" Http://www.springframework.org/schema/beans http ://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http:// Www.springframework.org/schema/context/spring-context.xsd "> <!--Introduce property profiles--> <bean class=" com.xxx.xx
X.xxx.xxx "> <property name=" Locations "> <list> <value>
File:/project-sit/config/xxx/some.properties </value> <value>
File:/project-sit/config/xxx/jdbc.properties </value> </list> </property> </bean> </beans>
4. This can be a good war package, directly into the server, and then put the sit configuration file into the configuration folder, so that every time without modifying the configuration file, directly packaged, redeploy OK. Copy code to be aware of. Here is an example of a lot of things being deleted. Hope not to mislead fellow students, learn from each other.
—————-the road of automation is still very long, if fully automatic need 100 steps, then this place can be regarded as the first step. The road long its repair far XI, I will go up and down and non-stop, masturbate, plagiarism, copy.