我正在使用 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>
并将changelog文件放在resources文件夹中。 db.changelog-master.xml
现在Spring引导首先在类路径中查找db.changelog-master.yaml并抛出这样的异常。
找不到更改日志位置:类路径资源[db / changelog / db.changelog-master.yaml
要修复问题,我在我的课程中添加了如下所示的bean,并尝试设置changeLog proprty。
@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:错误 创建名为'sampleDataJpaApplication'的bean:注入 自动连接依赖失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException:不能 autowire字段: org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties sample.data.jpa.SampleDataJpaApplication.properties;嵌套异常 是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有 合格的bean类型 [org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties] 找到依赖:预计至少有1个bean符合条件 autowire候选人这种依赖。依赖注释: {@ org.springframework.beans.factory.annotation.Autowired(所需=真)}
引起:org.springframework.beans.factory.BeanCreationException: 无法自动装配字段: org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties sample.data.jpa.SampleDataJpaApplication.properties;嵌套异常 是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有 合格的bean类型 [org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties] 找到依赖:预计至少有1个bean符合条件 autowire候选人这种依赖。依赖注释: {@ org.springframework.beans.factory.annotation.Autowired(所需=真)}
请在此处提供输入,为什么我会收到此异常,或者是否有任何其他可用方法来覆盖同一个类,以便我可以更改liquibase属性的changeLog属性。
答案 0 :(得分:11)
我不完全确定更改日志的确切运行时路径是什么,但为什么不使用&#34; liquibase。*&#34; application.properties
中的属性?你应该可以省略Liquibase
@Bean
并让Boot为你做。
如果您希望添加自己的Liquibase
@Bean
,请接受提示,并确保定义LiquibaseProperties
bean(例如,通过声明@EnableConfigurationProperties(LiquibaseProperties.class)
)。< / p>