Article directory
1. Scene description
Spring boot + Maven packaging, projects often use different environments to package different configuration files, such as the connected database, configuration file, log file level and so on.
2. Solutions
Defined in pom.xml file
2.1 real code
<project> <dependencies> </dependencies> <profiles> <profile> <id>dev</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <deploy.type>dev</deploy.type> </properties> </profile> <profile> <id>prod</id> <properties> <deploy.type>prod</deploy.type> </properties> </profile> </profiles> <build> <resources> <resource> <directory>src/main/profiles/${deploy.type}</directory> </resource> <resource> <directory>src/main/resources/</directory> </resource> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> </resource> </resources> <plugins> <plugin> <artifactId>maven-war-plugin</artifactId> <version>3.0.0</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>8</source> <target>8</target> </configuration> </plugin> </plugins> </build> </project>
2.2 code description
The point is that this line of code, combined with maven, can package different folders.
<resource> <directory>src/main/profiles/${deploy.type}</directory> </resource>
2.3 renderings:
2.3.1 program directory
2.3.2 maven directory
You need to package that environment. Double click it after checking.
If I think it's OK, I'll like it in the upper right corner.
If you have any inaccuracies or questions, you can communicate in the discussion area / QQ / wechat public account, thank you!