1、创建正常的spring boot项目,测试demo启动成功。
2、增加配置文件夹profiles,创建不同的环境配置文件
3、pom文件配置生效项,有多个环境配置多少个
<profiles>
<profile>
<!-- DEV environment-->
<id>dev</id>
<properties>
<profiles.active>dev</profiles.active>
</properties>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
</profile>
<profile>
<!-- SIT environment-->
<id>local</id>
<properties>
<profiles.active>local</profiles.active>
</properties>
</profile>
<profile>
<!-- UAT environment-->
<id>uat</id>
<properties>
<profiles.active>uat</profiles.active>
</properties>
</profile>
</profiles>
4、修改环境配置文件,设置本地启动默认环境配置文件
通过修改<activeByDefault>true</activeByDefault>的属性来设置启动默认的环境配置文件。下图为本地启动时,默认为读取uat环境的配置文件
5、备注:<activeByDefault>false</activeByDefault>时,默认读取dev环境的配置文件。
控制台输出:
6、no profiles are currently active报错问题
如果百度其他答案都无法解决这个问题,很有可能是你的项目类型写错了。正确的项目类型为jar。
报错信息:
控制台输出:
Description:
Cannot determine embedded database driver class for database type NONE
Action:
If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).