部署到Glassfish时未调用@PostConstruct方法

时间:2012-06-07 08:39:59

标签: maven-2 ejb glassfish-3 war liquibase

我打算使用LiquiBase来管理数据库,我希望每次将Web应用程序部署到Glassfish 3.1时都要运行它。为了做到这一点,我写了下面的课:

@Singleton
@Startup
public class LiquibaseWrapper {

    @Resource(name = "jdbc/mydatabase")
    private DataSource dataSource;

    @PostConstruct
    @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
    public void doLiquibaseUpdate() {
        ResourceAccessor fileOpener = new ClassLoaderResourceAccessor();
        DatabaseFactory databaseFactory = DatabaseFactory.getInstance();
        Database database = null;
        try {
            database = databaseFactory
                    .findCorrectDatabaseImplementation(new Jdbc Connection(
                            dataSource.getConnection()));
            Liquibase liquibase = new Liquibase("ChangeLog.xml",
                    fileOpener, database);
            liquibase.update("");
        } catch (DatabaseException e) {
            // TODO: handle error
        } catch (SQLException e) {
            // TODO: handle error
        } catch (LiquibaseException e) {
            // TODO: handle error
        }
    }
}    

问题在于,当我通过Eclipse将应用程序部署到服务器上时,不会执行doLiquiBaseUpdate()。当我从中构建WAR文件并手动部署它时,将执行该方法。

我有点困惑为什么在通过eclipse进行部署时不会运行LiquiBaseUpdate()。

其他可能有用的信息:     - 正在使用Maven 2构建WAR     - 使用JSF 2.1     - 数据库是MySQL     - 使用LiquiBase 2.0.3     - Eclipse Indigo with Glassfish服务器工具1.7.3

0 个答案:

没有答案