我的团队一直在尝试将我们现有的Grails应用从1.3.7升级到2.1.0。经过很多挫折,包括更新我们的整个测试套件,一切都在我们的本地机器上按预期运行。但是,一旦我们将应用程序放在我们的WAS 8 WebSphere服务器上,我们在尝试访问任何主页时遇到了一个奇怪的错误。以下是一个例子
No signature of method: com.app.Product.findAll() is applicable for argument types: () values: []
Possible solutions: findAll(), findAll(), findAll(groovy.lang.Closure), findAll(java.lang.Object), findAll(java.lang.String), findAll(groovy.lang.Closure). Stacktrace follows:
groovy.lang.MissingMethodException: No signature of method: com.app.Product.findAll() is applicable for argument types: () values: []
Possible solutions: findAll(), findAll(), findAll(groovy.lang.Closure), findAll(java.lang.Object), findAll(java.lang.String), findAll(groovy.lang.Closure)
....
进一步向下的堆栈跟踪是这样的:
....
Caused by: org.codehaus.groovy.grails.web.servlet.mvc.exceptions.ControllerExecutionException: Runtime error executing action
... 47 more
Caused by: java.lang.reflect.InvocationTargetException
... 47 more
Caused by: groovy.lang.MissingMethodException: No signature of method: com.app.Product.findAll() is applicable for argument types: () values: []
Possible solutions: findAll(), findAll(), findAll(groovy.lang.Closure), findAll(java.lang.Object), findAll(java.lang.String), findAll(groovy.lang.Closure)
at com.app.controllers.DomainTablesController$_closure2.doCall(DomainTablesController.groovy:26)
... 47 more
我添加了一些测试代码来检查,findAll()
,getAll()
和list()
方法都抛出相同的错误。我不是Grails大师,但看起来缺少标准的GORM方法。我们使用Maven将Grails WAR封装在服务器上安装的EAR中。这是我们的pom.xml的依赖项部分。它只是使用grails create-pom
命令创建的干净版本稍作修改。
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>1.8.6</version>
</dependency>
<dependency>
<groupId>org.grails</groupId>
<artifactId>grails-dependencies</artifactId>
<version>${grails.version}</version>
<exclusions>
<exclusion>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</exclusion>
</exclusions>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.grails</groupId>
<artifactId>grails-plugin-testing</artifactId>
<version>${grails.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>mail</artifactId>
<version>1.0.1</version>
<scope>runtime</scope>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>jquery</artifactId>
<version>1.7.2</version>
<scope>runtime</scope>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>resources</artifactId>
<version>1.1.6</version>
<scope>runtime</scope>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>webxml</artifactId>
<version>1.4.1</version>
<scope>runtime</scope>
<type>zip</type>
</dependency>
</dependencies>
关于项目的更多信息:我们将grails挂在现有DB2遗留数据库上。检查WAR Maven生成,我可以看到存在grails-datastore-gorm
和grails-hibernate
JARS。所以我很遗憾为什么在应用程序中无法访问基本的GORM方法。
任何人都有任何见解或建议将不胜感激。感谢
编辑:
添加hibernate和grails-hibernate插件依赖项后,访问登录页面时会出现新错误。没有grails-hibernate插件,登录页面显示正常并且登录按预期工作。新错误是:
Error Page Exception:
Error Message: javax.servlet.ServletException: SRVE0207E: Uncaught initialization exception created by servlet
Error Code: 0
Target Servlet:
Error Stack:
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 'lobHandlerDetector' while setting bean property 'lobHandler'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lobHandlerDetector': Invocation of init method failed; nested exception is
org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class 'com.ibm.db2.jcc.DB2Driver' for connect URL
...
...
...
Caused by: java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(DriverManager.java:453)
at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
... 35 more
我们正在部署的服务器上已经设置了驱动程序,并且1.3.7版本没有问题找到db2驱动程序或连接到数据库。想法?
答案 0 :(得分:0)
我认为hibernate从2.0开始被转移到单独的依赖项。*,因此您可能需要添加以下dependencies
:
<dependency>
<groupId>org.grails</groupId>
<artifactId>grails-hibernate</artifactId>
<version>${grails.version}</version>
</dependency>
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>hibernate</artifactId>
<version>${grails.version}</version>
<scope>compile</scope>
<type>zip</type>
</dependency>
并删除此依赖项:
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>1.8.6</version>
</dependency>
groovy-all
默认打包在Grails中,但我不确定该版本是否为1.8.6。如果您要从exclude
明确使用1.8.6然后groovy-all
grails-dependencies
,然后添加上述依赖项。
很高兴: -
如果可能,您可以尝试升级到最新版本的Grails 2.3.7稳定版本,因为您已经完成了升级过程。
我知道这将是一个陡峭的岩石与管理层攀登。切换到Gradle。 ;)