source

LiquiBase 문제 , 클래스 경로 리소스 [db/changelog/db.changelog-master.yaml]이(가) 없으므로 URL로 해결할 수 없습니다.

itover 2023. 3. 18. 08:31
반응형

LiquiBase 문제 , 클래스 경로 리소스 [db/changelog/db.changelog-master.yaml]이(가) 없으므로 URL로 해결할 수 없습니다.

리퀴바이스와 스프링부츠를 통합하는데 문제가 있습니다.아래와 같이 pom 파일에 리퀴베이스 의존성을 추가하였습니다.

    <dependencies>

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

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

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

    </dependencies>

src/main/resources에서 db/changelog 폴더를 만들었습니다.db 폴더에는 다음과 같은 내용이 포함된 liquibase-change.xml 파일이 있습니다.

<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.1.xsd">

    <include file="changelog/01-create-employee-scheme.xml" relativeToChangelogFile="true"/>
    <include file="changelog/02-data-insert-employees.xml" relativeToChangelogFile="true"/>

</databaseChangeLog>

changelog 폴더에는 다음 파일이 있습니다.

  • 01-create-create-syslog.xml
<changeSet id="01" author="xy">

    <createTable tableName="employee">
        <column name="id" type="int">
            <constraints nullable="false" primaryKey="true"/>
        </column>
        <column name="firstname" type="varchar(25)">
            <constraints nullable="false"/>
        </column>
        <column name="lastname" type="varchar(25)">
            <constraints nullable="false"/>
        </column>
    </createTable>

</changeSet>
  • 02-data-insert-module.xml
<insert tableName="employee">
    <column name="id" valueNumeric="1"/>
    <column name="firstname" value="x"/>
    <column name="lastname" value="y"/>
</insert>

spring boot의 응용 프로그램 속성 파일에서 다음과 같은 설정을 했습니다.application.properties

#Liquibase 
liquibase.change-log=classpath:db/liquibase-changelog.xml
spring.liquibase.enabled=true

#H2 DB 
spring.jpa.hibernate.ddl-auto=none
spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:mem:employeedb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=password
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect

스프링 부트 어플리케이션을 기동했을 때 표시되는 에러는 다음과 같습니다.

2020-03-14 13:22:54.557 ERROR 5804 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.ChangeLogParseException: Error parsing classpath:/db/changelog/db.changelog-master.yaml
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1108) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
    at com.github.rshtishi.payroll.employee.EmployeeApplication.main(EmployeeApplication.java:13) ~[classes/:na]
Caused by: liquibase.exception.ChangeLogParseException: Error parsing classpath:/db/changelog/db.changelog-master.yaml
    at liquibase.parser.core.yaml.YamlChangeLogParser.parse(YamlChangeLogParser.java:83) ~[liquibase-core-3.8.7.jar:na]
    at liquibase.Liquibase.getDatabaseChangeLog(Liquibase.java:217) ~[liquibase-core-3.8.7.jar:na]
    at liquibase.Liquibase.update(Liquibase.java:190) ~[liquibase-core-3.8.7.jar:na]
    at liquibase.Liquibase.update(Liquibase.java:179) ~[liquibase-core-3.8.7.jar:na]
    at liquibase.integration.spring.SpringLiquibase.performUpdate(SpringLiquibase.java:366) ~[liquibase-core-3.8.7.jar:na]
    at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:314) ~[liquibase-core-3.8.7.jar:na]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1855) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1792) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
    ... 18 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:195) ~[spring-core-5.2.4.RELEASE.jar:5.2.4.RELEASE]
    at liquibase.integration.spring.SpringLiquibase$SpringResourceOpener.getResourcesAsStream(SpringLiquibase.java:613) ~[liquibase-core-3.8.7.jar:na]
    at liquibase.util.StreamUtil.singleInputStream(StreamUtil.java:186) ~[liquibase-core-3.8.7.jar:na]
    at liquibase.parser.core.yaml.YamlChangeLogParser.parse(YamlChangeLogParser.java:26) ~[liquibase-core-3.8.7.jar:na]
    ... 25 common frames omitted

속성을 지정했는데 왜 [db/changelog/db.changelog-master.yaml] 파일을 검색하는지 이해할 수 없습니다.liquibase.change-log=classpath:db/liquibase-changelog.xmlapplication.properties 파일에 저장됩니다.

안부 전해요.

를 사용해 보세요.spring.liquibase.change-log(그뿐만 아니라)liquibase.change-log같은 문제에 직면했을 때, 이것은 나에게 효과가 있었습니다.

이 솔루션은 Jira Tracker의 CORE-3459호에도 언급되어 있습니다.

LiquibaseProperties액화효소 구성을 가지다

@ConfigurationProperties(prefix = "spring.liquibase", ignoreUnknownFields = false)  

따라서 property/yml 파일에는 liquibase에 대한 sprig 접두사가 있어야 합니다.

spring:
  liquibase:
    enabled: true
    drop-first: false
    change-log: classpath:db/liquibase-changelog.xml
    default-schema: public

올바른 자국이 있는지 확인합니다.

저도 같은 문제에 직면했어요.테스트 클래스의 @ContextConfiguration을 @SpringBoot로 대체.테스트하고 성공했어왜 먹혔는지 모르겠어.

저 같은 경우에는selectingIDE디렉토리resources~하듯이test resources일반 디렉토리가 고친 것과는 다릅니다.

Intellij Idea 2022.1

변경 후IDE존경하기 시작했다application.yml이 점에서.directory.

언급URL : https://stackoverflow.com/questions/60683101/liquibase-problem-class-path-resource-db-changelog-db-changelog-master-yaml

반응형