当然classpath是基础,已懂。
项目中在非classpath下建立不同环境的properties文件,右侧选择的哪个profile则在classpath下生成的所有配置文件用到的环境配置中的值都是右侧指定的profile的环境配置文件的。如果右侧没有选择任何profile,则使用的是pom.xml中配置为true的 profile来生成classpath下的配置文件,如果都为false的话则使用外层<properties> 下的<env>dev</env>指定的来生成。优先级:右侧,里properties,外properties
<properties>
<env>pre</env>
<ihhotel-version>1.0-SNAPSHOT</ihhotel-version>
<spring-version>4.2.7.RELEASE</spring-version>
<mybatis-version>3.4.1</mybatis-version>
<mybatis-spring-version>1.3.0</mybatis-spring-version>
<druid-version>1.0.11</druid-version>
<mysql-connection-version>5.1.24</mysql-connection-version>
<pagehelper-version>4.0.1</pagehelper-version>
</properties>
<build>
<filters>
<filter>src/main/filters/${env}.properties</filter>:路径必须有不然找不到配置文件
</filters>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF8</encoding>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
在pom.xml中配置false和true来选择是否默认激活:
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<env>dev</env>
</properties>
</profile>
<profile>
<id>jd-test</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<env>jd-test</env>
</properties>
</profile>
<profile>
<id>pre</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<env>pre</env>
</properties>
</profile>
<profile>
<id>prod</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<env>prod</env>
</properties>
</profile>
</profiles>
<properties>
<env>jd-test</env>
<ihhotel-version>1.0-SNAPSHOT</ihhotel-version>
<spring-version>4.2.7.RELEASE</spring-version>
<mybatis-version>3.4.1</mybatis-version>
<mybatis-spring-version>1.3.0</mybatis-spring-version>
<druid-version>1.0.11</druid-version>
<mysql-connection-version>5.1.24</mysql-connection-version>
<pagehelper-version>4.0.1</pagehelper-version>
</properties>
<dependencies>
<build>
<filters>
<filter>src/main/filters/${env}.properties</filter>
</filters>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF8</encoding>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
IDEA里右侧选择的话按它来,否则项目会根据pom中的<properties> <env>pre</env>来选择