IntelliJ IDEA meven的配置文件管理
java后台项目中会用到meven对项目进行编译、导包、发布
等操作。
pom中可以通过配置变量,来配置文件直接的映射关系。
通过meven可以管理整个项目的配置文件:
实现思路:
1、通过pom.xml文件配置系统配置文件
2、通过业务配置文件调用
3、应用层文件调用业务配置文件
思路图:
实现代码:
<!-- 定义环境 start-->
<profiles>
<profile>
<id>localhost</id>
<properties>
<env>localhost</env>
<name>manage</name>
</properties>
</profile>
</profiles>
<build>
<filters>
<filter>src/main/resource/filter/${env}.properties</filter> <!-- 得到localhost 映射到resource下的filter目录下 -->
</filters>
<resources>
<resource>
<directory>src/main/resource</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
<finalName>${name}</finalName> <!-- 得到manage-->
</build>
调用配置文件:
jdbc.properties:
# mysql config
jdbc.driver.class=com.mysql.jdbc.Driver
jdbc.db_maxActive=50
jdbc.url=${jdbc.url}
jdbc.username=${jdbc.username}
jdbc.password=${jdbc.password}
系统配置文件:
localhost.properties:
host=192.168.1.154
port=6379
password=tyhd4545259879
jdbc.url=jdbc:mysql://119.29.19.173:3306/majiang?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
jdbc.username=root
jdbc.password=4165587
downloadHost=http\://192.168.1.154\:8080/download/version