Connect different databases through MAVEN configuration test environment and development environment author and Source: Tong Lingbao Jade-Blog Park collection to →_→: This article is from:
Macaidong blog url: http://www.makaidong.comSummary: Connect different databases through the MAVEN configuration test environment and the 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 >
<>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>
10<Directory>${project.basedir}/src/test/resources</directory>
11 <filtering< Span style= "color: #0000ff;" >>true</filtering >
12 </testresource>
13 </testresources
14 </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