1

I'm trying to run my LiquibaseProducer in WildFly 9.0.2. This is my Producer class:

package nl.itris.mjop.database;
import liquibase.integration.cdi.*;
import liquibase.integration.cdi.annotations.*;
import liquibase.resource.*;

import ********** 

@Singleton
@Startup
@Dependent
public class LiquibaseProcducer {


@Resource(lookup="java:jboss/datasources/PostgresDS")
private static DataSource myDataSource;

@Produces @LiquibaseType
public CDILiquibaseConfig createConfig() {
    System.out.println("============= liquibase createConfig entry =============");
    CDILiquibaseConfig config = new CDILiquibaseConfig();
    config.setChangeLog("liquibase/parser/core/xml/simpleChangeLog.xml");
    System.out.println("============= liquibase createConfig exit =============");
    return config;
}

@Produces @LiquibaseType
public DataSource createDataSource() throws SQLException {
    System.out.println("============= liquibase createDataSource entry =============");

    return getDataSource();
}

@Produces @LiquibaseType
public ResourceAccessor create() {
    System.out.println("============= liquibase create entry =============");
    return new ClassLoaderResourceAccessor(getClass().getClassLoader());
}

public static DataSource getDataSource() {

    if (myDataSource == null) {
      /* Workaround for failing  @Resource(lookup="java:jboss/datasources/PostgresDS") */

        try {
            System.out.println("============= liquibase  datasource lookup via initial context  workaround =============");
            InitialContext ctx = new InitialContext();
            myDataSource = (DataSource) ctx.lookup("java:jboss/datasources/PostgresDS");
        } catch(NamingException ne) {
            ne.printStackTrace();
        }
    }
    return myDataSource;
}
}

When I (re) deploy my WAR file in WildFly, this producer is not doing anything! I do not see any error messages in my log files, I do not see any system.out messages that I put in the producer methods.

The producer class seems to be loaded and recognized by WildFly hence this log fragment:

2016-11-30 10:58:53,662 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-7) JNDI bindings for session bean named LiquibaseProcducer in deployment unit deployment "mjop-elements.war" are as follows:

java:global/mjop-elements/LiquibaseProcducer!nl.itris.mjop.database.LiquibaseProcducer
java:app/mjop-elements/LiquibaseProcducer!nl.itris.mjop.database.LiquibaseProcducer
java:module/LiquibaseProcducer!nl.itris.mjop.database.LiquibaseProcducer
java:global/mjop-elements/LiquibaseProcducer
java:app/mjop-elements/LiquibaseProcducer
java:module/LiquibaseProcducer

I'm out of options. Why is my producer not executed? What am I doing wrong?

Any help is appreciated!

My beans.xml is like this:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                   http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
   version="1.1" bean-discovery-mode="all">
 </beans>   
  • yes that right. sorry for my typo – Jan vd Klok Nov 30 '16 at 13:00
  • Try changing `@Dependent` for `@ApplicationScoped`. My first guess is that your bean is not initialized anywhere (from CDI point of view). Besides combining `@Singleton`, `@Startup` (both EJB annotations) and setting that as `@Dependent` is kind of weird. EJB Singleton is in principle much closer to Application scope than Dependent. – Siliarus Nov 30 '16 at 13:09
  • Can you share your `beans.xml` file? – John Ament Nov 30 '16 at 22:24
  • The `@Singleton`, `@Startup` and `@Dependent` annotations come from Liquibase CDI variant implementation documentation !!! Changing `@Dependent` with `@ApplicationScope` does not fix the problem. I have added the beans.xml to the original question. It's my understanding that an empty beans.xml will be sufficient nowadays. – Jan vd Klok Dec 01 '16 at 07:19

0 Answers0