[SpringBoot从类路径加载配置文件属性

问题描述 投票:0回答:1

我的问题:

是否可以在启动期间从类路径中加载配置application-persist.yml

application-persist.yml是我的外部库的一部分,并且包含spring.datasource配置

myexternallib.jar
- config
  - application-persist-dev.yml
    spring:
      datasource:
        jdbc-url: url-to-dev-database
        username: xxx
        password: xxx
        driver-class-name: org.postgresql.Driver
  - application-persist-prod.yml
    spring:
      datasource:
        jdbc-url: url-to-prod-database
        username: xxx
        password: xxx
        driver-class-name: org.postgresql.Driver

在我的春季启动项目中,myexternallib.jar作为依赖项包含在内并且我想从类路径中加载配置:

我项目的application.yml

spring:
  profiles:
    include: persist
    active: dev, persist-dev

问题是:当我启动我的应用程序时,启动失败,并出现以下异常:

Caused by: java.lang.IllegalArgumentException: dataSource or dataSourceClassName or jdbcUrl is required.

因为在启动过程中无法正确读取application-persist-dev.yml。

我该如何解决?

spring-boot configuration datasource
1个回答
0
投票

[Spring Boot's reference documentation此时非常清楚:

java -jar myproject.jar --spring.config.location=classpath:/application-persist.yml
© www.soinside.com 2019 - 2024. All rights reserved.