项目中不同环境使用不同的配置文件,可以使用maven的profiles配置。个人感觉maven的插件配置教程比较杂,为防止以后忘记,记录一个现在再用的,能用的配置。
环境:
spring boot2.2.6 jdk8 maven3.5.2
项目目录结构:
maven配置如下:
<profiles>
<!--开发-->
<profile>
<id>dev</id>
<properties>
<!--此处为自定义属性,其他地方可以使用${demo}引用该值-->
<ccat.env>dev</ccat.env>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<!--生产-->
<profile>
<id>prod</id>
<properties>
<!--此处为自定义属性,其他地方可以使用${demo}引用该值-->
<ccat.env>prod</ccat.env>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArguments>
<extdirs>${project.basedir}/src/main/resources/lib</extdirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>springboot项目启动主类全限定类名</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- 资源文件处理插件,必须配置 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
<!-- 最后生成的资源文件 -->
<resources>
<!-- 需要的资源都包含进来 -->
<resource>
<directory>src/main/resources/cert</directory>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<!-- 包含mapper文件--><!-- 这里配置打包mapper -->
<include>com/**/*.xml</include>
</includes>
</resource>
<!-- 不同环境的资源文件 -->
<resource>
<directory>src/main/resources/${ccat.env}</directory>
</resource>
</resources>
</build>
总结:
其他也没有深入研究,现在这样也够用,记录一下这个能用的配置,后面有需求再研究。本人技术有限,欢迎交流