8上使用CDI运行Liquibase

8上使用CDI运行Liquibase

本文介绍了在Wildfly 8上使用CDI运行Liquibase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在WildFly 8.1.0.Final上使用CDI运行Liquibase脚本,但出现此错误:

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

我的POM具有以下依赖性:

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>

我的CDI Bean如下:

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

我的项目是一个简单的WAR.我在做什么错了?

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

推荐答案

LiquibaseStarter没有bean定义的注释.在班级添加@Dependent.

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

这篇关于在Wildfly 8上使用CDI运行Liquibase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 18:53