How to Solve Springboot configurate environment file Error

preface

When configuring multiple environment files for springboot, you need to configure multiple YML files. The configuration before version 2.4 is as follows:

spring: 
  profiles:
    active: dev

But if SpringBoot’s version 2.4 later, it’s a reward.

org.springframework.boot.context.config.InvalidConfigDataPropertyException: Property ‘spring.profiles.active[0]’ imported from location ‘class path resource [application-work.yml]’ is invalid in a profile specific resource [origin: class path resource [application-work.yml] - 9:7]

 

Solution:

General layout changes as follows:

spring:
  config:
    activate:
       on-profile:
          - dev

Of course, it can also be solved by returning the spring boot version to before 2.4

Read More: