2、在pom.xml设置
- <build>
- <resources>
- <resource>
- <!--把相对应的独特资源(dev,test,prod这三种的一种)声明,排除jsp文件-->
- <directory>src/main/resources.${deploy.type}</directory>
- <excludes>
- <exclude>*.jsp</exclude>
- </excludes>
- </resource>
- <resource>
- <!--声明公共资源-->
- <directory>src/main/resources</directory>
- </resource>
- </resources>
- </build>
- <!--分别设置开发,测试,生产环境-->
- <profiles>
- <profile>
- <id>dev</id>
- <activation>
- <activeByDefault>true</activeByDefault>
- </activation>
- <properties>
- <deploy.type>dev</deploy.type>
- </properties>
- </profile>
- <profile>
- <id>test</id>
- <properties>
- <deploy.type>test</deploy.type>
- </properties>
- </profile>
- <profile>
- <id>prod</id>
- <properties>
- <deploy.type>prod</deploy.type>
- </properties>
- </profile>
- </profiles>
-Dmaven.test.skip=true 为测试打包和测试编译,-P后面接的是所需要打包环境的id,如dev开发环境,test测试环境,如果不写-P,默认为dev即开发环境
mvn clean package -Dmaven.test.skip=true -Ptest
如图所示,选上对应的环境,然后运行tomcat即可
2、eclipse
右键项目配置,然后选上maven,输入你需要的环境id,如dev
springboot 配置多资源方式,建立不同的环境的资源application.properties是公共资源
在application添加环境替换设置,deploy.type为pom.xml配置的多环境
spring.profiles.active=@deploy.type@
联系客服