繁体   English   中英

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

[英]Property 'spring.profiles.active' imported from location 'class path resource [application-dev.yml]' is invalid

我将 Spring 云应用程序更新为最新的 Spring 启动版本 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

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

如果文件名为application-dev.yml ,则无需提及 spring.profiles.active属性( spring 启动新版本)

在您的 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

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 文件中删除此条目。

从 2.4 版(Spring Boot 2.4)开始:

不能再从配置文件特定文档激活配置文件。

https://spring.io/blog/2020/08/14/config-file-processing-in-spring-boot-2-4

一种方法是使用spring.profiles.group.*

  1. application-dev.yml删除: profiles: active: local

  2. 重命名application-dev.yml -> application-dev123.yml

  3. application.properties定义组“dev”: spring.profiles.group.dev=local,dev123

现在名为“dev”的组替换了以前名为“dev”的配置文件。

在本地运行时,只需在 JVM 运行时 Arguments 中添加以下内容。 如果您有 Docker 文件,您也可以在入口点中添加以下文件。

-Dspring.config.use-legacy-processing=true

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM