Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring-boot with Liquibase Overloading Property

I am using Spring boot and Liquibase. Using this url as guidelines

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

In pom.xml, the below entry is present so that spring boot knows about liquibase.

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

and put the changelog file in resources folder. db.changelog-master.xml

Now Spring boot first tring to find db.changelog-master.yaml in classpath and throwing the exception like this.

Cannot find changelog location: class path resource [db/changelog/db.changelog-master.yaml

To Fix the Issue, I have added the bean like below in my class and tried to set 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);
}

}

but it is failing with the message.

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

Please provide the inputs here, why i am getting this exception or Is there any any other available way to override the same class so that i can change the changeLog property of liquibase properties.

like image 920
Kul Bhushan Prasad Avatar asked Jun 23 '14 20:06

Kul Bhushan Prasad


1 Answers

I'm not entirely sure what the exact runtime path to your change log is, but why don't you just use the "liquibase.*" properties in application.properties? You should be able to leave out the Liquibase @Bean and let Boot do it for you.

If you prefer to add you own Liquibase @Bean then take the hint and make sure you define a LiquibaseProperties bean as well (e.g. by declaring @EnableConfigurationProperties(LiquibaseProperties.class)).

like image 109
Dave Syer Avatar answered Sep 18 '22 20:09

Dave Syer