SpringBoot:解决Property ‘spring.profiles‘ imported from location ‘class path resource 问题
•
Jave
一、在学习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提示信息来找错误,不要死脑筋,一直检查代码错误。这次问题出在版本的原因。
我们需要养成会看代码提示来进行解决问题的习惯,脑子要灵活点。
本文来自网络,不代表协通编程立场,如若转载,请注明出处:https://net2asp.com/4239c4c756.html
