3

尝试将我的 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 插件运行我的数据库迁移。

我找到了一个关于这个主题的邮件列表帖子,

看起来我实际上可以在迁移中添加:package current 以解决问题。也许我应该一直这样?

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

有人知道吗?

4

1 回答 1

5

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

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

为了跟进,我通过在与文件夹结构匹配的迁移脚本文件的开头添加包声明来解决问题。不确定是 Grails 更改还是 Groovy 更改导致了问题,但是文件正在使用声明的包结构编译到目标/类目录中(在这种情况下什么都没有,导致它们位于根文件夹)。但是,Grails 正在检测文件结构中的文件并创建带有匹配路径的 Spring FileSystemResources。这些被传递给 DefaultGrailsApplication 构造函数,并且 ClassLoader 未能在匹配位置找到类。

grails-app/migrations/releases/release_1/foo.groovy -> 目标/类/foo.class

通过在 foo.groovy 的开头添加“package release.release_1”,然后发生以下情况:

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

然后 ClassLoader 找到 FileSystemResource 对应的类文件。

于 2013-05-01T22:08:37.240 回答