SpringBoot:解决Property ‘spring.profiles‘ imported from location ‘class path resource 问题

一、在学习SpringBoot配置profile的时候,.yml文件内容明明跟老师敲的一模一样,但还是报org.springframework.boot.context.config.InvalidConfigDataPropertyException: Property 'spring.profiles' imported from location 'class path resource [application.yml]' is invalid and should be replaced with 'spring.config.activate.on-profile' [origin: class path resource [application.yml] - 21:13]错误

二、.yml文件源代码

---
server:
  port: 8081

spring:
  profiles: dev

---
server:
  port: 8082

spring:
  profiles: pro


---
server:
  port: 8083

spring:
  profiles: test


---
spring:
  profiles:
    active: test

三、报如下错误

四、问题原因

通过Debug运行提示: should be replaced with 'spring.config.activate.on-profile'(需要你改为现在的这种代码格式)

五、改完后源代码

---
server:
  port: 8081
spring:
  config:
    activate:
      on-profile: dev

---
server:
  port: 8082
spring:
  config:
    activate:
      on-profile: pro


---
server:
  port: 8083
spring:
  config:
    activate:
      on-profile: test

---
spring:
  profiles:
    active: test

六、运行结果

七、反思

当按照老师讲的走时,遇到问题,需要及时通过Debug提示信息来找错误,不要死脑筋,一直检查代码错误。这次问题出在版本的原因。

我们需要养成会看代码提示来进行解决问题的习惯,脑子要灵活点。 

  • 18
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值