簡體   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