Liquibase CDI不满足DataSource类型的依赖关系

时间:2015-08-06 10:20:53

标签: java jboss cdi wildfly liquibase

我正在从JBoss 7.1迁移到Wildfly 8.当我尝试部署包含用于DB的Liquibase脚本的模块时,我收到以下错误:

at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1904) [jboss-msc-1.2.0.Final.jar:1.2.0.Final]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_45]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_45]
    at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_45]
Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type DataSource with qualifiers @LiquibaseType
  at injection point [BackedAnnotatedField] @Inject @LiquibaseType private liquibase.integration.cdi.CDILiquibase.dataSource
  at liquibase.integration.cdi.CDILiquibase.dataSource(CDILiquibase.java:0)

根据文档设置制作人:

public class LiquibaseProducer {

    private static final String MASTER_CHANGE_LOG_FILE="master_change_log.xml";

    @Resource(mappedName="java:jboss/datasources/MyDS")
    private DataSource dataSource;

    @Produces @LiquibaseType
    public CDILiquibaseConfig createConfig() {
        CDILiquibaseConfig config = new CDILiquibaseConfig();
        config.setChangeLog(MASTER_CHANGE_LOG_FILE);
        return config;
    }

    @Produces @LiquibaseType
    public DataSource createDataSource() throws SQLException {
        return dataSource;
    }

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

}

我尝试按照this answer中的描述添加@Dependent注释,但没有运气。此外,尝试使用@Startup/@ApplicationScoped/@Stateless,但这也没有帮助。

最初我们使用的是Liquibase 3.0.2。现在,由于this Jira issue我升级到3.0.6,现在甚至升级到3.4.1 - 仍然没有。

通过启用调试,我可以看到LiquibaseProducer已注册:

11:27:53,180 DEBUG [org.jboss.weld.Bootstrap] (MSC service thread 1-7) WELD-000106: Bean: Producer Method [ResourceAccessor] with qualifiers [@LiquibaseType @Any] declared as [[BackedAnnotatedMethod] @Produces @LiquibaseType public com.server.database.LiquibaseProducer.create()]
11:27:53,180 DEBUG [org.jboss.weld.Bootstrap] (MSC service thread 1-7) WELD-000106: Bean: WELD|AbstractSyntheticBean|com.server.deployment.ear.ear/com.server.database-1.19.0-SNAPSHOT.war/WEB-INF/classes|BoundRequestContext
11:27:53,181 DEBUG [org.jboss.weld.Bootstrap] (MSC service thread 1-7) WELD-000106: Bean: WELD|AbstractSyntheticBean|com.server.deployment.ear.ear/com.server.database-1.19.0-SNAPSHOT.war/WEB-INF/classes|BoundSessionContext
11:27:53,181 DEBUG [org.jboss.weld.Bootstrap] (MSC service thread 1-7) WELD-000106: Bean: WELD|AbstractSyntheticBean|com.server.deployment.ear.ear/com.server.database-1.19.0-SNAPSHOT.war/WEB-INF/classes|HttpServletRequest
11:27:53,181 DEBUG [org.jboss.weld.Bootstrap] (MSC service thread 1-7) WELD-000106: Bean: WELD|AbstractSyntheticBean|com.server.deployment.ear.ear/com.server.database-1.19.0-SNAPSHOT.war/WEB-INF/classes|ServletContext
11:27:53,182 DEBUG [org.jboss.weld.Bootstrap] (MSC service thread 1-7) WELD-000106: Bean: Managed Bean [class com.server.database.LiquibaseProducer] with qualifiers [@Any @Default]
11:27:53,182 DEBUG [org.jboss.weld.Bootstrap] (MSC service thread 1-7) WELD-000106: Bean: WELD|AbstractSyntheticBean|com.server.deployment.ear.ear/com.server.database-1.19.0-SNAPSHOT.war/WEB-INF/classes|BoundConversationContext
11:27:53,183 DEBUG [org.jboss.weld.Bootstrap] (MSC service thread 1-7) WELD-000106: Bean: WELD|AbstractSyntheticBean|com.server.deployment.ear.ear/com.server.database-1.19.0-SNAPSHOT.war/WEB-INF/classes|HttpConversationContext
11:27:53,183 DEBUG [org.jboss.weld.Bootstrap] (MSC service thread 1-7) WELD-000106: Bean: WELD|AbstractSyntheticBean|com.server.deployment.ear.ear/com.server.database-1.19.0-SNAPSHOT.war/WEB-INF/classes|HttpSessionContext
11:27:53,183 DEBUG [org.jboss.weld.Bootstrap] (MSC service thread 1-7) WELD-000106: Bean: WELD|AbstractSyntheticBean|com.server.deployment.ear.ear/com.server.database-1.19.0-SNAPSHOT.war/WEB-INF/classes|HttpSessionDestructionContext
11:27:53,184 DEBUG [org.jboss.weld.Bootstrap] (MSC service thread 1-7) WELD-000106: Bean: WELD|AbstractSyntheticBean|com.server.deployment.ear.ear/com.server.database-1.19.0-SNAPSHOT.war/WEB-INF/classes|RequestContext
11:27:53,184 DEBUG [org.jboss.weld.Bootstrap] (MSC service thread 1-7) WELD-000106: Bean: WELD|AbstractSyntheticBean|com.server.deployment.ear.ear/com.server.database-1.19.0-SNAPSHOT.war/WEB-INF/classes|ApplicationContext
11:27:53,184 DEBUG [org.jboss.weld.Bootstrap] (MSC service thread 1-7) WELD-000106: Bean: WELD|AbstractSyntheticBean|com.server.deployment.ear.ear/com.server.database-1.19.0-SNAPSHOT.war/WEB-INF/classes|SingletonContext
11:27:53,184 DEBUG [org.jboss.weld.Bootstrap] (MSC service thread 1-7) WELD-000106: Bean: Producer Method [DataSource] with qualifiers [@LiquibaseType @Any] declared as [[BackedAnnotatedMethod] @Produces @LiquibaseType public com.server.database.LiquibaseProducer.createDataSource()]
11:27:53,184 DEBUG [org.jboss.weld.Bootstrap] (MSC service thread 1-7) WELD-000106: Bean: WELD|AbstractSyntheticBean|com.server.deployment.ear.ear/com.server.database-1.19.0-SNAPSHOT.war/WEB-INF/classes|Conversation
11:27:53,184 DEBUG [org.jboss.weld.Bootstrap] (MSC service thread 1-7) WELD-000106: Bean: Producer Method [CDILiquibaseConfig] with qualifiers [@LiquibaseType @Any] declared as [[BackedAnnotatedMethod] @Produces @LiquibaseType public com.server.database.LiquibaseProducer.createConfig()]

所以,如果现在想到它为什么不与Wildfly合作,我就出去了。最后一个想法是我的生产者生产不同的数据源,而不是Liquibase期望的,来自不同的rt.jar。不确定它是否有意义。

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

看起来你有一个耳朵部署。确保从CDILiquibase到生产者的可见性。从日志中,你的制作人似乎处于战争状态。如果CDILiquibase位于不同的模块中,则可能是问题所在。