简体   繁体   English

如何在执行 jar 时从外部配置文件访问类路径

[英]How to get access from external config file to classpath in executing jar

I develop Spring Boot 2.2.1 application.我开发了 Spring Boot 2.2.1 应用程序。 I have multiple profiles (application-{provile}.yml) and use liquibase for migrate database automatically.我有多个配置文件 (application-{provile}.yml) 并使用 liquibase 自动迁移数据库。 Everything works almost fine (if it is possible to say that about Java, lol).一切都几乎正常(如果可以说大约 Java,大声笑)。 But in production environment i have to pass config file as external yml file ourside from far .但是在生产环境中,我必须将配置文件作为外部 yml 文件从远处传递到我们身边

I am executing following shell to start application:我正在执行以下 shell 以启动应用程序:

java.exe -jar orgstructure-service-0.0.1-SNAPSHOT.jar --spring.profiles.active=prod -Dspring.config.location=./application-prod.yml

Application is starting and configs applies properly except liquibase.应用程序正在启动并且配置正确应用,但 liquibase 除外。 Liquibase use classpath for changelog configuration: Liquibase 使用类路径进行变更日志配置:

  liquibase:
    change-log: classpath:db/changelog/changelog.xml

But changelog is inaccessible from external (outside of jar) application.yml therefore liquibase can not apply migrations.但是更改日志无法从外部(jar 之外)application.yml 访问,因此 liquibase 无法应用迁移。 How to solve this issue and make liquibase to work in such environment?如何解决这个问题并使 liquibase 在这样的环境中工作?

I found solution of this problem, i've separated applicatiom-prod.yml on two files on of them applicatiom-prod.yml is stored inside./src/main/resources directory and it is packed inside jar, the second i called application-customization.yml and it is located separatedly from jar file but in same directory.我找到了这个问题的解决方案,我在两个文件上分离了 applicatiom-prod.yml,其中 applicatiom-prod.yml 存储在./src/main/resources 目录中,它打包在 jar 中,第二个我称为应用程序-customization.yml,它与 jar 文件分开但位于同一目录中。 application-prod.yml include seconds as follows: application-prod.yml 包含秒数如下:

  spring:
    profiles: 
      active: prod
      include:
        customization
    liquibase:
      change-log: classpath:db/changelog/changelog.xml

  logging:
    level:
      root: INFO
      org.springframework: INFO
      org.hibernate.SQL: INFO
      org.hibernate.type: INFO
      liquibase: INFO

Customization holds settings like database and authorization server connection and so on.自定义包含数据库和授权服务器连接等设置。

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

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