Grails 升级到 2.2.2 失败,迁移脚本出现 ClassNotFoundException

lovecherry 阅读:14 2024-11-01 17:39:52 评论:0

当我试图将我的 Grails 项目从 2.1.1 升级到 2.2.2 时,我得到了一个奇怪的堆栈跟踪,

| Error 2013-05-01 17:54:46,935 [localhost-startStop-1] ERROR context.GrailsContextLoader  - Error initializing the application: Error creating bean with name 'grailsApplication' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsConfigurationException: Class not found loading Grails application: devportal.schema.schema-0 
Message: Error creating bean with name 'grailsApplication' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsConfigurationException: Class not found loading Grails application: devportal.schema.schema-0 
   Line | Method 
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   138 | run      in java.util.concurrent.FutureTask 
|   895 | runTask  in java.util.concurrent.ThreadPoolExecutor$Worker 
|   918 | run      in     '' 
^   680 | run . .  in java.lang.Thread 
 
Caused by GrailsConfigurationException: Class not found loading Grails application: devportal.schema.schema-0 
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   138 | run      in java.util.concurrent.FutureTask 
|   895 | runTask  in java.util.concurrent.ThreadPoolExecutor$Worker 
|   918 | run      in     '' 
^   680 | run . .  in java.lang.Thread 
 
Caused by ClassNotFoundException: devportal.schema.schema-0 
->> 202 | run      in java.net.URLClassLoader$1 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   190 | findClass in java.net.URLClassLoader 
|   306 | loadClass in java.lang.ClassLoader 
|   303 | innerRun in java.util.concurrent.FutureTask$Sync 
|   138 | run . .  in java.util.concurrent.FutureTask 
|   895 | runTask  in java.util.concurrent.ThreadPoolExecutor$Worker 
|   918 | run . .  in     '' 
^   680 | run      in java.lang.Thread 

出于某种原因,它看起来像是在尝试从 Database Migrations plugin 运行我的数据库迁移.

我找到了一个 mailing list post关于这个问题,

It looks like I can actually add: package current to my migrations to fix the problem. Maybe I should have had this all along?

但是将我的包添加到我的脚本中并没有帮助(我什至尝试了 current)。

有人知道吗?

请您参考如下方法:

发帖后几乎直接找到了解决方案,

http://grails.1312388.n4.nabble.com/Nested-folder-for-database-migrations-in-Grails-2-2-x-td4642106.html

To follow up, I solved the problem by adding a package declaration to the beginning of the migration script files that matches the folder structure. Not sure if it's a Grails change or a Groovy change that caused the problem, but the files were being compiled into a the target/classes directory using the declared package structure (which in this case was nothing, resulting in them being at the root folder). However, Grails was detecting the files in the file structure and creating Spring FileSystemResources with paths to match that. These were passed to the DefaultGrailsApplication constructor and the ClassLoader failed to the find the classes at the matching locations.

grails-app/migrations/releases/release_1/foo.groovy -> target/classes/foo.class

By adding 'package releases.release_1' to the beginning of foo.groovy, then the following occurred:

grails-app/migrations/releases/release_1/foo.groovy -> target/classes/releases/release_1/foo.class

Then the ClassLoader found the corresponding class file for the FileSystemResource.


标签:Exception
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

关注我们

一个IT知识分享的公众号