gpt4 book ai didi

具有 Liquibase 重载属性的 Spring-boot

转载 作者:行者123 更新时间:2023-12-04 10:38:20 26 4
gpt4 key购买 nike

我正在使用 Spring Boot 和 Liquibase。
使用此网址作为指南

http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/

pom.xml ,存在以下条目,以便 spring boot 了解 liquibase。

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

并将更改日志文件放在资源文件夹中。
db.changelog-master.xml

现在 Spring Boot 首先尝试在类路径中找到 db.changelog-master.yaml 并抛出这样的异常。

找不到变更日志位置:类路径资源 [db/changelog/db.changelog-master.yaml

为了解决这个问题,我在我的类(class)中添加了如下所示的 bean 并尝试设置 changeLog 属性。
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class SampleDataJpaApplication {


@Autowired
LiquibaseProperties properties;
@Autowired
private DataSource dataSource;

@Bean
public SpringLiquibase liquibase() {
SpringLiquibase liquibase = new SpringLiquibase();
properties.setChangeLog("classpath:/db/changelog/db.changelog-master.xml");
liquibase.setChangeLog(this.properties.getChangeLog());
liquibase.setContexts(this.properties.getContexts());
liquibase.setDataSource(this.dataSource);
liquibase.setDefaultSchema(this.properties.getDefaultSchema());
liquibase.setDropFirst(this.properties.isDropFirst());
liquibase.setShouldRun(this.properties.isEnabled());
return liquibase;
}

public static void main(String[] args) throws Exception {
Logger logger = LoggerFactory.getLogger("SampleDataJpaApplication");
SpringApplication springApplication = new SpringApplication();
springApplication.run(SampleDataJpaApplication.class, args);
}

}

但它的消息失败了。

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sampleDataJpaApplication': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties sample.data.jpa.SampleDataJpaApplication.properties; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties sample.data.jpa.SampleDataJpaApplication.properties; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}



请在此处提供输入,为什么我会收到此异常,或者是否有任何其他可用的方法来覆盖同一类,以便我可以更改 liquibase 属性的 changeLog 属性。

最佳答案

我不完全确定更改日志的确切运行时路径是什么,但为什么不使用 application.properties 中的“liquibase.*”属性? ?您应该可以省略 Liquibase @Bean让 Boot 为您完成。

如果您更喜欢添加您自己的 Liquibase @Bean然后接受提示并确保您定义了 LiquibaseProperties bean 也是(例如通过声明 @EnableConfigurationProperties(LiquibaseProperties.class) )。

关于具有 Liquibase 重载属性的 Spring-boot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24374423/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com