解决 No active profile set, falling back to 1 default profile: “default“问题以及如何查看spring boot版本号
文章目录
- 1. 问题
- 2. 分析问题
-
- 2.1 检查yml配置文件
- 2.2 检查pom文件
- 2.3 检查配置的环境
- 3. 解决问题
- 4. 如何查看spring boot版本
1. 问题
今天,在启动项目时,出现了如下错误:

即 No active profile set, falling back to 1 default profile: "default"。
这个问题不是错误,因为它的日志级别是info(log.level = info),但上文的英文是什么意思呢?翻译成中文是:未设置激活的配置文件,回退到 1 个默认配置文件:“默认”。
我们在使用多配置文件时,比如application-dev.yml,application-prd.yml文件,如下图所示:

我们需要在配置文件中设置spring.profiles.active:local指令,如果不设置的话,会使用默认的配置文件application.yml(上文的中文翻译即是这个意思。)
假设我们把默认的配置文件application.yml删除了,程序就会报错,如下图所示:

我们还是把配置文件application.yml还原回来,因为,我们目的是为了解决这个提示: No active profile set, falling back to 1 default profile: "default"。
2. 分析问题
2.1 检查yml配置文件
- 检查
application.yml文件
# 端口号配置
server:
port: 8081
# 日志配置
logging:
level:
root: info
com.superjson.www: trace
config: "classpath:logback-spring.xml"
# spring 配置
spring:
# 指定哪个文件,比如dev.yml local.yml
profiles:
active: @spring.active@
# 需要将其设置为always,彩色打印日志
output:
ansi:
enabled: always
# 应用名称
application:
name: superJsonManager
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
password: 123456
username: root
url: jdbc:mysql://localhost:3306/superjson?useUnicode=true&characterEncoding=utf8&useSSL=false
# mybatis配置
mybatis:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
check-config-location: true
mapper-locations: classpath:mapper/*.xml
type-aliases-package: com.superjson.superjsonmanager.mapper
配置文件application.yml没有问题,即spring.profiles.active:@spring.active@动态指定哪个文件。
- 检查
application-local.yml文件
该文件是空文件,继承application.yml文件的配置,没有问题。
同理,application-dev.yml文件和application-prd.yml文件也是空文件,都继承application.yml文件的配置
2.2 检查pom文件
pom文件如下所示,没有发现任何问题:
<profiles>
<profile>
<id>local</id>
<properties>
<spring.active>local</spring.active>
</properties>
<activation>
<!--默认激活的文件,即application-local.yml文件-->
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>dev</id>
<properties>
<spring.active>dev</spring.active>
</properties>
</profile>
<profile>
<id>prd</id>
<properties>
<spring.active>prd</spring.active>
</properties>
</profile>
</profiles>
2.3 检查配置的环境
- edit configurations

- 环境是否配置
spring.profiles.active=local

环境已配置了spring.profiles.active=local,这里没有问题。
综上检查,所有的配置都没有问题,那么,问题出现在哪里呢?只能是spring boot的版本问题。
3. 解决问题
既然知道是spring boot的版本,如果你的spring boot是2.5以前的版本,采用上述配置没有问题,即如下代码所示:
spring:
# 指定哪个文件,比如dev.yml local.yml
profiles:
active: @spring.active@
# 需要将其设置为always,彩色打印日志
output:
ansi:
enabled: always
......
但我的spring boot版本是2.7.1 便不再适合上述的配置。因而,我们需要修改application.yml文件中的spring的配置,如下所示:
# spring 配置
spring:
# 指定哪个文件,比如dev.yml local.yml
config:
activate:
on-profile:
- @spring.active@
# 需要将其设置为always,彩色打印日志
output:
ansi:
enabled: always
......
此时,便能正常启动项目文件了,如下图所示:

4. 如何查看spring boot版本
- 找到pom文件,查看parent标签,如下图所示:

- 如果你没有修改spring默认的banner,可以在如下位置查看其版本

转载请注明:解决 No active profile set, falling back to 1 default profile: “default“问题以及如何查看spring boot版本号 | 胖虎的工具箱-编程导航
