问题
Got a Grails 2 app and executing run-app works fine, run-war fails:
2011-12-24 12:43:40,996 [Thread-2] ERROR context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pluginManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Lgrails/test/mixin/services/ServiceUnitTestMixin;
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.NoClassDefFoundError: Lgrails/test/mixin/services/ServiceUnitTestMixin;
at java.lang.Class.privateGetDeclaredFields(Class.java:2291)
at java.lang.Class.getDeclaredField(Class.java:1880)
... 5 more
Caused by: java.lang.ClassNotFoundException: grails.test.mixin.services.ServiceUnitTestMixin
... 7 more
Just run into this problem after having a pretty much flawless experience of working with Grails 2,
How has this come about is a complete headscratcher for me:
java.lang.NoClassDefFoundError: Lgrails/test/mixin/services/ServiceUnitTestMixin;
... any feedback will be most appreciated.
回答1:
I encountered a similar issue and solved it by doing the following in order:
- Delete everything in the target directory
- grails clean
- grails compile
- grails run-war
回答2:
I had the exact same issue and the accepted answer didn't work for me, so I dived a bit closer...
What I found is a class MyServiceTests
that had somehow managed to sneak out of grails-app/test/unit/
into grails-app/services/
; probably during some kind of package rename refactoring. After moving MyServiceTests
back to test/unit everything has worked fine again.
回答3:
The package name of the controller has to match the package name of the domain class. Make sure your package names are consistent throughout the project, including lower and upper case in the package name. Some IDEs are not consistent in updating accidental typos throughout the project.
回答4:
I had a similar situation to johanneslink.
The application wouldn't start in Tomcat. Checking catalina.out showed a ClassNotFoundException caused by grails.test.mixin.services.ServiceUnitTestMixin
I used grep to look for all occurrences of 'ServiceUnitTestMixin' in the whole of the application folder (starting in the parent of grails-app). I found that somehow I'd imported grails.test.mixin.Mock into a Controller.
Once I removed that and clean/compiled the war file it deployed and started just fine.
来源:https://stackoverflow.com/questions/8626076/grails-2-run-war-java-lang-classnotfoundexception-grails-test-mixin-service