java - 在 Glassfish 下运行多个 Grails 应用程序时出错

标签 java grails glassfish

我使用 Grails (V2.0.0.RC1) 编写了两个小型 hello world 应用程序,我想使用 Glassfish (v3.1) 部署它们。

如果我将其单独部署在 Glassfish 上的应用程序之一,则该应用程序可以正常工作,并且我可以通过 http://t1-0.1http 访问它://t2-0.1。但是,如果我部署其中一个应用程序,然后部署另一个应用程序(以便访问我的网站的人都可以使用这两个应用程序),则第二个部署命令会显示以下错误消息:

c:>asadmin deploy t2-0.1.war

remote failure: Error occurred during deployment: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'hibernateProperties' while setting bean property 'hibernateProperties'; nested exception is org.springframework.beans.factory.BeanCreationException: Errorcreating bean with name 'hibernateProperties': Cannot resolve reference to bean'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init methodfailed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Database may be already in use: "Locked by another process". Possible solutions: closeall other connection(s); use the server mode; SQL statement:null/1349c415392c6dc06a3e7086cd1bb075c7881fc0650 [90020-147]). Please see server.log for more details.

这是怎么回事?我认为 Grails 及其对 Hibernate 的使用有一些特殊之处(否则 Glassfish 不会提示允许我拥有两个可以一起工作的应用程序)。但也许我误读了错误消息?有人有什么建议吗?

最佳答案

事实证明,问题在于我滥用了 Grails 提供的默认配置。在文件 DataSource.groovy 中,每个应用程序都被赋予一个指向数据库的指针,默认情况下该指针如下所示:

development {
    dataSource {
        dbCreate = "create-drop" 
        url = "jdbc:h2:mem:devDb;MVCC=TRUE"
    }
}

问题在于,多个应用程序将被赋予相同的配置,并且多个应用程序之间的底层基于内存的 h2 数据库引用发生冲突。因此,几个“hello world”示例应用程序的解决方案是更改其中一个引用。例如:

development {
    dataSource {
        dbCreate = "create-drop" 
        url = "jdbc:h2:mem:devDb2;MVCC=TRUE"
    }
}

当然,在生产代码中,您可能最终会引用真实的数据库,然后您的应用程序自然会在其数据库引用中进行协作。

关于java - 在 Glassfish 下运行多个 Grails 应用程序时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8778200/

相关文章:

json - 后端只接受纯文本,不接受 JSON,只接受名称而不是 id

java - 如何以编程方式将 LinearLayout 对象添加到我的上下文中?

model-view-controller - Grails-路径中的用户名

hibernate - Grails 和 Amazon SimpleDB

grails - 如何使用Grails Web框架将CSS和javascript包含到主模板头部

tomcat - Tomcat无法处理的Java EE场景

java - 如何处理java中的类型有界通配符

java - 如何解决重复的 zip 条目

java - 在 Java 中打印 opencv 矩阵内容

glassfish - Apache JENA TDB 文件在使用 Web 应用程序创建后被锁定