2

I am trying to run Liquibase scripts using CDI on WildFly 8.1.0.Final and I am getting this error:

Unsatisfied dependencies for type ResourceAccessor with qualifiers @LiquibaseType

My POM has these dependencies:

<dependencies>
    <dependency>
        <groupId>org.liquibase</groupId>
        <artifactId>liquibase-core</artifactId>
        <version>3.3.0</version>
    </dependency>
    <dependency>
        <groupId>org.liquibase</groupId>
        <artifactId>liquibase-cdi</artifactId>
        <version>3.3.0</version>
    </dependency>
    <dependency>
        <groupId>com.mattbertolini</groupId>
        <artifactId>liquibase-slf4j</artifactId>
        <version>1.2.1</version>
    </dependency>
</dependencies>

My CDI Bean is as follows:

import javax.annotation.Resource;
import javax.enterprise.inject.Produces;
import javax.sql.DataSource;

import liquibase.integration.cdi.CDILiquibaseConfig;
import liquibase.integration.cdi.annotations.LiquibaseType;
import liquibase.resource.ClassLoaderResourceAccessor;
import liquibase.resource.ResourceAccessor;

public class LiquibaseStarter {
    @Produces
    @LiquibaseType
    public CDILiquibaseConfig createConfig() {
        CDILiquibaseConfig config = new CDILiquibaseConfig();
        config.setChangeLog("liquibase/parser/core/xml/simpleChangeLog.xml");
        return config;
    }

    @Resource(name="java:jboss/datasources/ExampleDS")
    private DataSource ds;

    @Produces
    @LiquibaseType
    public DataSource createDataSource() {
        return ds;
    }

    @Produces
    @LiquibaseType
    public ResourceAccessor create() {
        return new ClassLoaderResourceAccessor(getClass().getClassLoader());
    }
}

My project is a simple WAR. What am I doing wrong?

lexsoto
  • 23
  • 3

1 Answers1

8

LiquibaseStarter has no bean-defining annotation. Add @Dependent at class-level.

Harald Wellmann
  • 12,615
  • 4
  • 41
  • 63
  • 1
    Thank you! That was it. Unfortunately the example provided by Liquibase site did not have this annotation. http://www.liquibase.org/documentation/cdi.html – lexsoto Nov 18 '14 at 01:03
  • 1
    It depends on the CDI spec level and on your configuration whether or not a bean-defining annotation is required. Presumably, the Liquibase example was written for CDI 1.0. – Harald Wellmann Nov 18 '14 at 10:29
  • 1
    I can update the docs but don't use CDI enough to know for sure the change. Would I just add @Dependent to public class LiquibaseProvider? – Nathan Voxland Nov 21 '14 at 15:34
  • 1
    Yes, that would do. It won't break anything for CDI 1.0, and it's the default solution for CDI 1.1+. It would help casual users, and for advanced CDI users it should be obvious when and how to replace the default. – Harald Wellmann Nov 21 '14 at 18:58