Grails upgrade to 2.2.2 fails with ClassNotFoundException on migration script

StackOverflow https://stackoverflow.com/questions/16327231

  •  13-04-2022
  •  | 
  •  

Вопрос

I'm getting a strange stack trace when trying to upgrade my Grails project from 2.1.1 to 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

For some reason it looks like it is trying to run my database migrations from the Database Migrations plugin.

I found a mailing list post on the subject,

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

But adding my package to my scripts didn't help (I even tried current).

Anyone have any idea?

Это было полезно?

Решение

Found a solution almost directly after posting,

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top