spring类路径资源[db/changelog/db.changelog master.yaml]无法解析为url,因为它不存在;运行jar文件时

wwwo4jvm  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(994)

我想构建一个可执行的jar文件,但在cmd中运行它时遇到了问题。在intellij中运行应用程序时,它可以正常启动。我知道基本上确切的问题已经存在,但它的答案( spring.liquibase.change-log 而不仅仅是 liquibase.change-log )似乎不适用于我的情况。
运行jar文件时,错误的最后一部分如下所示(我希望这是最重要的部分):

Caused by: liquibase.exception.ChangeLogParseException: Error parsing classpath:/db/changelog/db.changelog-master.yaml
        at liquibase.parser.core.yaml.YamlChangeLogParser.parse(YamlChangeLogParser.java:83)
        at liquibase.Liquibase.getDatabaseChangeLog(Liquibase.java:216)
        at liquibase.Liquibase.update(Liquibase.java:189)
        at liquibase.Liquibase.update(Liquibase.java:178)
        at liquibase.integration.spring.SpringLiquibase.performUpdate(SpringLiquibase.java:368)
        at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:316)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1845)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1782)
        ... 61 common frames omitted
Caused by: java.io.FileNotFoundException: class path resource [db/changelog/db.changelog-master.yaml] cannot be resolved to URL because it does not exist
        at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:202)
        at liquibase.integration.spring.SpringLiquibase$SpringResourceOpener.getResourcesAsStream(SpringLiquibase.java:601)
        at liquibase.util.StreamUtil.singleInputStream(StreamUtil.java:186)
        at liquibase.parser.core.yaml.YamlChangeLogParser.parse(YamlChangeLogParser.java:26)
        ... 68 common frames omitted

应用程序属性:

spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
spring.datasource.username=p******
spring.datasource.password=t****
spring.datasource.driver-class-name=org.postgresql.Driver
spring.liquibase.change-log=classpath:db/changelog/db.changelog-master.xml

db.changelog-master.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
        xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
                      http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">
    <include  file="db/changelog/db.changelog_tables.xml"/>
</databaseChangeLog>

pom.xml文件:

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>

        <dependency>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-core</artifactId>
        </dependency>

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>5.7.0</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

就像有同样问题的人一样,我不明白它为什么要搜索文件 [db/changelog/db.changelog-master.yaml] 当我指定属性时: spring.liquibase.change-log=classpath:db/changelog/db.changelog-master.xml 在application.properties文件中。或者我完全误解了smt,因为在intellij中运行应用程序和运行jar文件是两件完全不同的事情?
我会感激任何帮助。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题