在使用Spring Boot引入JOOQ时,我遇到了Liquibase的错误并进行了相应处理的经历

背景 – Background

我正在学习Spring Boot。

    • IDE:STS4

 

    各種バージョン:Java13, Spring boot2, JOOQ 3.13.1

是的。

在学习Spring Boot期间,我有一种想要用方法来编写SQL的感觉。

在使用Spring默认的JPA进行简单的数据库访问时,当进行表连接时,感觉不太合适。
我想起以前在工作中编写方法基础的SELECT语句,于是开始寻找类似的库。

我发现了一种名为JOOQ的查询构造器型ORM,所以决定开始使用。

引入的方式

我决定放弃。
在使用Postgres的同时,我对目标数据库表的表关联源代码的自动生成并不感到太困扰。

发生错误!

在尝试启动WEB应用程序时,并无编译错误,但出现了以下错误。

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 jp.ken.PasswordmanagerApplication.main(PasswordmanagerApplication.java:10) ~[main/: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

这是什么啊。。。顺便问一下,Liquibase是什么?

借鉴先人的智慧,https://qiita.com/opengl-8080/items/37beac5e210f5363af4b

大致上看起来像是一个数据库管理工具。
看起来很方便,但现在并不需要。
所以,有没有办法能够不关注它呢?

在进行调查的同时尝试进行下一个设置。

    1. 在src/main/resources中创建一个名为db的文件夹

 

    1. 在db文件夹中创建一个名为db.changelog-master.yaml的文件

 

    在application.properties中追加内容

db.changelog-master.yaml的内容

databaseChangeLog:
  - changeSet:
       author: authorName
       id: changelog-1.0

清空文件或只保留”databaseChangeLog:” 仍然导致错误,因此我只找到了最小必需内容,如上所示。

在application.properties文件中添加内容

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

给我提供上述的 YAML 文件。

在以下网站上,可以了解到创建文件的相关信息。
https://stackoverflow.com/questions/41990295/java-illegalstateexception-cannot-find-changelog-location-class-path-resourc

另外,可以从以下网站推测出所需的最小限度的yaml元素。
https://qiita.com/opengl-8080/items/37beac5e210f5363af4b

以上錯誤已解決!真是太好了,真是太好了。

广告
将在 10 秒后关闭
bannerAds