简体   繁体   中英

Error when mixing java and groovy code in Grails Spring Data application

I am wanting to create a Grails application with a number of java source files. These java files are to give me access to an embedded Neo4J graph by means of spring-data-neo4j.

(I would use the Grails Neo4J GORM plugin instead, but for the fact that it doesn't work in anything higher than Grails 2.3.5 - I'm using 2.4.3 - and even when using 2.3.5, the sample application provided by the developer has errors when I run it).

I want to create a series of java classes that represent the nodes that are present in the graph, which spring-data-neo4j will then allow me to access in Grails as POJOs (as discussed in point 1 of the second answer on SO here ). I am using this Spring Data tutorial here as a starting point. I've copied the Person.java and PersonRepository.java classes to src/java. I'm then running "grails run-app" - I don't expect anything to happen, just for Grails to compile the java sources and then start normally (I'll then work on importing some of the code in Application.java into a 3rd java class to actually use the classes).

However, I get the following error and Grails crashes:

context.ContextLoader Context initialization failed java.lang.NoSuchMethodError: org.springframework.expression.spel.SpelParserConfiguration.(Lorg/springframework/expression/spel/SpelCompilerMode;Ljava/lang/ClassLoader;)V at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) context.GrailsContextLoaderListener Error initializing the application: org.springframework.expression.spel.SpelParserConfiguration.(Lorg/springframework/expression/spel/SpelCompilerMode;Ljava/lang/ClassLoader;)V java.lang.NoSuchMethodError: org.springframework.expression.spel.SpelParserConfiguration.(Lorg/springframework/expression/spel/SpelCompilerMode;Ljava/lang/ClassLoader;)V at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecu tor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) | Error Forked Grails VM exited with error | Server running. Browse to http://localhost:8080/

If I run the java example application as a basic java program (build and run it using "gradle run") then it works as advertised.

Is there something I need to do to get java code to compile properly inside a Grails spring data application?

It appears to be related to a version mismatch for the dependencies. The sample code uses the Gradle spring-boot plugin to sort out transitive dependencies. However, this can't be used in my project as I am using the gradle-grails plugin, which specifically forbids using the Java or Groovy plugins (and the spring-boot plugin requires the Java one).

When I changed the dependencies from 4.1.1 (latest, 6 Nov 14) to 4.0.6 of these two dependencies, the error went away:

compile "org.springframework:spring-context:4.0.6.RELEASE"
compile "org.springframework:spring-tx:4.0.6.RELEASE"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM