Class CDILiquibase

java.lang.Object
liquibase.integration.jakarta.cdi.CDILiquibase
All Implemented Interfaces:
jakarta.enterprise.inject.spi.Extension

@ApplicationScoped public class CDILiquibase extends Object implements jakarta.enterprise.inject.spi.Extension
A CDI wrapper for Liquibase.

Example Configuration:

This CDI configuration example will cause liquibase to run automatically when the CDI container is initialized. It will load db-changelog.xml from the classpath and apply it against myDataSource.

Various producers methods are required to resolve the dependencies, i.e.

 @Dependent
 public class CDILiquibaseProducer {

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

   @Produces @LiquibaseType
   public DataSource createDataSource() throws SQLException {
      jdbcDataSource ds = new jdbcDataSource();
      ds.setDatabase("jdbc:hsqldb:mem:test");
      ds.setUser("sa");
      ds.setPassword("");
      return ds;
   }

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

 }