Connect different database authors and sources through MAVEN configuration test environment and development environment: Tong Lingbao Jade-Blog Park collection to →_→: This article from:
Macaidong BlogURL: http://www.makaidong.com Summary: Connect different databases with MAVEN configuration test environment and development environment
"Connect different databases through MAVEN configuration test environment and development environment": Keywords: Configure test environment development environment with MAVEN to connect different databases
Connect different databases through the MAVEN configuration test environment and the development environment
Operation in 3 steps
1. Define profiles in the pom of the data persistence layer to define a different profile for the development and test environment
<profiles>
<profile>
<id>dev</id>
<activation>
<activebydefault>true</activebydefault>
</activation>
<properties>
<jdbc.driverclassname>com.mysql.jdbc.driver</jdbc.driverclassname>
<jdbc.url>jdbc:mysql://192.168.1.100:3306/test</jdbc.url>
<jdbc.username>test</jdbc.username>
<jdbc.password >test2011</jdbc.password >
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<jdbc.driverclassname>com.mysql.jdbc.driver</jdbc.driverclassname>
<jdbc.url>jdbc:mysql://192.168.1.200:3306/test</jdbc.url>
<jdbc.username>test</jdbc.username>
<jdbc.password >test2011</jdbc.password >
</properties>
</profile>
</profiles>
Define the Profile:jdbc.url property with the ID of Dev as jdbc:mysql://192.168.1.100:3306/test
The Profile:jdbc.url attribute with ID test is defined as Jdbc:mysql://192.168.1.200:3306/test
2. Define the resources filter in the POM of the data persistence layer
Other database configurations are placed in/src/main/resources and/src/test/resources, adding resource filtering to the POM
1 <build>
2 <resources>
3 <resource>
4 <directory>${project.basedir}/src/main/resources</directory>
5 <filtering>true</filtering>
6 </resource>
7 </resources>
8 <testresources>
9 <testresource>
Ten <directory>${project.basedir}/src/test/resources</directory>
<filtering>true</filtering>
</testresource>
</testresources>
</build>
3. Define the JDBC connection file in/src/main/resources and/src/test/resources jdbc.properties
1 Jdbc.driverclassname=${jdbc.driverclassname}
3 Jdbc.url=${jdbc.url}
5 Jdbc.username=${jdbc.username}
7 Jdbc.password =${jdbc.password}
Running the MVN command after the previous 3 steps will execute the profile with the ID dev (due to the addition of <activebydefault>true</activebydefault> configuration in the ID dev configuration)
Adding-ptest runs after the MVN command executes the profile with ID test.
After being configured as above, Maven looks for the properties defined in profile in the files in src/main/resources/and/src/test/resources (that is, the jdbc.properties configured in step 3rd) ( such as Jdbc.properties in ${jdbc.driverclassname}, etc.).
Connect different databases with the MAVEN configuration test environment and development environment