从位置“类路径资源 \[application-dev.yml\]”导入的属性“spring.profiles.active”无效

新手上路,请多包涵

我将 Spring 云应用程序更新为最新的 Spring boot 版本 2.5.0。

但是在启动期间我得到这个异常:

 11:05:05.038 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
org.springframework.boot.context.config.InvalidConfigDataPropertyException: Property 'spring.profiles.active' imported from location 'class path resource [application-dev.yml]' is invalid in a profile specific resource [origin: class path resource [application-dev.yml] from skyshop-mail-1.0.jar - 42:17]
        at org.springframework.boot.context.config.InvalidConfigDataPropertyException.lambda$throwOrWarn$1(InvalidConfigDataPropertyException.java:125)

应用.yml

 spring:
    application:
        name: mail-service
    profiles:
        active: dev

应用程序-dev.yml 文件:

 logging:
    file:
        name: ${java.io.tmpdir}/application.log
    level:
        com:
            backend: DEBUG
        org:
            springframework: DEBUG
            springframework.web: DEBUG
jwt:
    expiration: 86400
    secret: test112322
server:
    port: 8020
    servlet:
        context-path: /mail
spring:
    application:
        name: mail-service
    profiles:
        active: local
    data:
        web:
            pageable:
                one-indexed-parameters: true # Fix pagination starting number to start from 1
        rest:
            basePath: /mail
    jackson:
        default-property-inclusion: non_null
    jmx:
        enabled: false
    datasource:
        url: jdbc:mariadb://localhost:3306/database
        driverClassName: org.mariadb.jdbc.Driver
        jpa:
            hibernate:
                ddl-auto: update
            properties:
                hibernate:
                    dialect: org.hibernate.dialect.MariaDBDialect
            show-sql: true
        username: root
        password: qwerty
    oauth2:
        resource:
            jwt:
                key-pair:
                    alias: mytestkey
                    store-password: mystorepass
info:
    build:
        version: 1.0
eureka:
    client:
        serviceUrl:
            defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}
    instance:
        preferIpAddress: true

你知道我该如何解决这个问题吗?

原文由 Peter Penzov 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 2.5k
2 个回答

在您的 application-dev.yml 中,您声明:

 spring:
    application:
        name: mail-service
    profiles:
        active: local

2个解决方案:

  1. 将 application-dev.yml 重命名为 application-local.yml 并使用本地配置文件
  2. 在 application-dev.yml 中将 spring.profiles.active 更改为 dev

原文由 user3088799 发布,翻译遵循 CC BY-SA 4.0 许可协议

Spring Boot 2.4 改进了 application.properties 和 application.yml 文件的处理方式。

详情请看这里: https ://github.com/spring-projects/spring-boot/wiki/Spring-Boot-Config-Data-Migration-Guide

长话短说:如果你有一个 application-local.yml 并且你在里面定义了

spring:
profiles:
    active: local

然后只需删除 yaml 文件中的此项。

原文由 René Winkler 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题