Pet*_*zov 50 java spring spring-boot spring-cloud
我将 Spring cloud 应用程序更新到最新的 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)
Run Code Online (Sandbox Code Playgroud)
应用程序.yml
spring:
application:
name: mail-service
profiles:
active: dev
Run Code Online (Sandbox Code Playgroud)
application-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
Run Code Online (Sandbox Code Playgroud)
你知道我该如何解决这个问题吗?
Ren*_*ler 48
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
Run Code Online (Sandbox Code Playgroud)
然后只需删除 yaml 文件中的此条目即可。
Abu*_*din 12
较新的 Spring Boot 版本对基于环境的命名约定非常严格。您无法在运行时注入应用程序属性。您需要为每个环境创建 application-{env}.properties,这将根据活动配置文件进行选择。
\n但是,如果您对执行所有这些更改感到不舒服,您仍然可以使用旧处理器。只需在运行 Spring Boot 时添加以下内容作为 JVM 参数即可。如果您使用 Docker,请确保将其添加到 Dockerfile Entrypoint 中。
\n-Dspring.config.use-legacy-processing=true\nRun Code Online (Sandbox Code Playgroud)\n\n
从 2.4 版(Spring Boot 2.4)开始:
无法再从配置文件特定文档激活配置文件。
https://spring.io/blog/2020/08/14/config-file-processing-in-spring-boot-2-4
前进的一种方法可能是使用spring.profiles.group.*
从application-dev.yml删除:profiles: active: local
重命名application-dev.yml->application-dev123.yml
在application.properties定义组“dev”中: spring.profiles.group.dev=local,dev123
名为“dev”的组现在取代了以前名为“dev”的配置文件。
小智 8
在您的 application-dev.yml 中,您声明:
spring:
application:
name: mail-service
profiles:
active: local
Run Code Online (Sandbox Code Playgroud)
2个解决方案:
| 归档时间: |
|
| 查看次数: |
97725 次 |
| 最近记录: |