Dom*_*ier 21 cdi ejb-3.1 flyway
在hibernate挂接我的JBoss AS 7.1之前,我试图在我的应用程序中运行flyway.我尝试使用@javax.ejb.Startup注释,但是在初始化Hibernate并检查数据库方案之后执行此操作.
所以据我所知,我们可以使用CDI扩展,它在初始化Hibernate之前挂钩.对飞路的开箱即用有什么支持吗?如果没有,有没有人试过这样做呢?
Dom*_*ier 37
好吧,我终于找到了如何做到这一点:我不得不使用Hibernate Integration API.这是我必须编写的完整代码:
public class FlywayIntegrator implements Integrator {
@Override
public void integrate(final Configuration configuration, final SessionFactoryImplementor sessionFactoryImplementor, final SessionFactoryServiceRegistry sessionFactoryServiceRegistry) {
final Flyway flyway = new Flyway();
flyway.setDataSource(....);
flyway.migrate();
}
@Override
public void integrate(final MetadataImplementor metadataImplementor, final SessionFactoryImplementor sessionFactoryImplementor, final SessionFactoryServiceRegistry sessionFactoryServiceRegistry) {
//no-op
}
@Override
public void disintegrate(final SessionFactoryImplementor sessionFactoryImplementor, final SessionFactoryServiceRegistry sessionFactoryServiceRegistry) {
//no-op
}
}
Run Code Online (Sandbox Code Playgroud)
如果有人对更多细节感兴趣,我创建了一个github项目,该项目演示了:https://github.com/dobermai/Hibernate-Flyway-Integration
| 归档时间: |
|
| 查看次数: |
16355 次 |
| 最近记录: |