简体   繁体   中英

war file with Cache implementation works fine on grails 2.4.4 but fails on tomcat 7

I am using grails 2.4.4 and trying to implement cache in it. I have added cache-api.jar in the lib folder and in the build path and have added a maven dependency compile "org.jsr107.ri:cache-ri-impl:1.0.0-RC1". When I run the war as grails run-app, the cache works fine. But when I deploy the same war on tomcat, it gives me the following exception.

[http-apr-9090-exec-2] ERROR errors.GrailsExceptionResol
ver  - NoSuchMethodError occurred when processing request: [POST] /pharma/login
javax.cache.CacheManager.createCache(Ljava/lang/String;Ljavax/cache/configuratio
n/Configuration;)Ljavax/cache/Cache;. Stacktrace follows:
org.codehaus.groovy.grails.web.servlet.mvc.exceptions.ControllerExecutionExcepti
on: Executing action [login] of controller [pharma.PharmaController]  ca
used exception: Runtime error executing action
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.
java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:615)
        at java.lang.Thread.run(Thread.java:745)
Caused by: org.codehaus.groovy.grails.web.servlet.mvc.exceptions.ControllerExecu
tionException: Runtime error executing action
        ... 3 more
Caused by: java.lang.reflect.InvocationTargetException
        ... 3 more
Caused by: java.lang.NoSuchMethodError: javax.cache.CacheManager.createCache(Lja
va/lang/String;Ljavax/cache/configuration/Configuration;)Ljavax/cache/Cache;
        at trident.TridentCache.getCache(TridentCache.java:32)
        at trident.pharma.PharmaService.login(PharmaService.groovy:107)
        at trident.pharma.PharmaController.login(PharmaController.groovy:46)
        ... 3 more

What baffles me is the war works fine in grails environment and the cache implementation also works perfectly but the same war when deployed on Tomcat, it throws the above exception.

Without knowing which version of grails, tomcat and jdK were in place is quite difficult to understand what's going on, but looking merely to the exception seems that your Grails implementation and the Tomcat you used have two different versions of the javax.cache.CacheManager class.

hence the missing method...

UPDATE: the package you mentioned org.jsr107.ri:cache-ri-impl:1.0.0-RC1 uses the javax.cache » cache-api 1.0.0-RC1

That particular version has this method signature in CacheManager class

  <K, V, C extends Configuration<K, V>> Cache<K, V> createCache(String cacheName,
                                                            C configuration)
  throws IllegalArgumentException;

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