LiquiBase problem , class path resource [db/changelog/db.changelog-master.yaml] cannot be resolved to URL because it does not exist
Asked Answered
H

7

33

I am having a problem integrating liquibase with springboot. I have added the liquibase dependency in the pom file like below:

    <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>

In the src/main/resources I have created the folders db/changelog. In the db folder it is located the liquibase-change.xml file that has content below:

<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>

In the folder changelog are located the files:

  • 01-create-employee-scheme.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-employees.xml
<insert tableName="employee">
    <column name="id" valueNumeric="1"/>
    <column name="firstname" value="x"/>
    <column name="lastname" value="y"/>
</insert>

In the application properties file of spring boot i have made the configuration below. 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

The error that is thrown when i start the spring boot application is like below:

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

I don't understand why it is searching for file [db/changelog/db.changelog-master.yaml] when I have specified the property : liquibase.change-log=classpath:db/liquibase-changelog.xml in the application.properties file.

Regards.

Homerhomere answered 14/3, 2020 at 13:9 Comment(5)
I believe it should be spring.liquibase.change-log=...". liquibase.change-log` (without spring prefix) is deprecated.Palatable
Ervin Szilagyi is right and you also have wrong path to your changelog. As you wrote that you put your changelog to db/changelog folder then it should be spring.liquibase.change-log=classpat:db/changelog/liquibase-change.xml. Btw db/changelog/db.changelog-master.yam is default spring's value.Veronica
Thank you, but I fixed the other mistakes.Homerhomere
adding spring prefix worked!Rottweiler
@Veronica I have the same issue. How can I fix it? Here is the link : #75511095Fauch
C
33

Try using the spring.liquibase.change-log property (and not just liquibase.change-log). This worked for me when I faced the same problem.

This solution is also mentioned in issue CORE-3459 in the Jira tracker.

Caterina answered 3/8, 2020 at 9:41 Comment(1)
liquibase.change-log is deprecated. It has to be spring.liquibase.change-logTerritorialism
C
8

Spring LiquibaseProperties has configuration for liquibase

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

So, in property/yml file should have sprig prefix for liquibase

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

make sure you have right indentation

Crwth answered 15/9, 2021 at 11:52 Comment(0)
B
2

In the pom.xml file set the version in the parent tag 3.0.2. At this moment 3.0.3 does not work

Bimestrial answered 26/2, 2023 at 19:32 Comment(0)
G
1

In my case selecting in IDE directory resources as test resources not like an ordinary directory fixed it.

Intellij Idea 2022.1

After that change IDE started to respect application.yml in this directory.

Gee answered 29/6, 2022 at 15:39 Comment(0)
O
0

I also faced same issue. Replaced @ContextConfiguration in Test class with @SpringBootTest and it worked. Not sure why it worked.

Obsession answered 10/8, 2021 at 17:54 Comment(0)
G
0

I'd faced the same problem, but with application.yml file, the problem was identation, as mentioned above.

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

like this should work,

in your case:

try this:

spring.liquibase.change-log=classpath:db/liquibase-changelog.xml
spring.liquibase.enabled=true  
Goodfornothing answered 10/2, 2023 at 12:26 Comment(0)
S
0

In my case, the only thing that IDE wanted was just a Maven Re-Import

Septuor answered 31/5 at 12:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.