parsing ehcache.xml not working in grails

851 views
Skip to first unread message

he...@raumo.de

unread,
Jul 3, 2018, 4:00:19 AM7/3/18
to ehcache-users
  1. What version of Ehcache you are currently using;
  2. Paste the configuration for the Cache/CacheManager you have an issue with;
  3. Add any name and version of other library or framework you use Ehcache with (e.g. Hibernate);
  4. Providing JDK and OS versions maybe useful as well.
1: cache-ehcache:3.0.0.M1
2: application.yml: 
grails:
    cache:
        ehcache:
            ehcacheXmlLocation: 'ehcacheCustom.xml'
            lockTimeout: 200
ehcacheCustom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="false">

     Default Cache Configuration, with name 'default'
    <defaultCache maxElementsInMemory="50" eternal="false"
                  overflowToDisk="false" memoryStoreEvictionPolicy="LFU" />

    <cache name="employeeCache" maxElementsInMemory="50" eternal="false"
           overflowToDisk="false" memoryStoreEvictionPolicy="LFU" />

</ehcache>
3: cache-ehcache:3.0.0.M1 in grails 3.3.1
4: jdk 1.8

error: 
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'grailsCacheAdminService': Unsatisfied dependency expressed through field 'org_grails_plugin_cache_GrailsCacheManagerAware__grailsCacheManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsCacheManager': Cannot resolve reference to bean 'ehcacheConfiguration' while setting bean property 'configuration'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ehcacheConfiguration': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [grails.plugin.cache.ehcache.DefaultXmlConfiguration]: Constructor threw exception; nested exception is org.ehcache.xml.exceptions.XmlConfigurationException: Error parsing XML configuration at file:/home/user/workspaces/api2-grails/grails-app/conf/ehcacheCustom.xml
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at grails.boot.GrailsApp.run(GrailsApp.groovy:83)
at grails.boot.GrailsApp.run(GrailsApp.groovy:387)
at grails.boot.GrailsApp.run(GrailsApp.groovy:374)
at grails.boot.GrailsApp$run.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
at api2.Application.main(Application.groovy:8)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsCacheManager': Cannot resolve reference to bean 'ehcacheConfiguration' while setting bean property 'configuration'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ehcacheConfiguration': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [grails.plugin.cache.ehcache.DefaultXmlConfiguration]: Constructor threw exception; nested exception is org.ehcache.xml.exceptions.XmlConfigurationException: Error parsing XML configuration at file:/home/user/workspaces/api2-grails/grails-app/conf/ehcacheCustom.xml
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1531)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1276)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585)
... 24 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ehcacheConfiguration': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [grails.plugin.cache.ehcache.DefaultXmlConfiguration]: Constructor threw exception; nested exception is org.ehcache.xml.exceptions.XmlConfigurationException: Error parsing XML configuration at file:/home/user/workspaces/api2-grails/grails-app/conf/ehcacheCustom.xml
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:279)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1193)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1095)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
... 37 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [grails.plugin.cache.ehcache.DefaultXmlConfiguration]: Constructor threw exception; nested exception is org.ehcache.xml.exceptions.XmlConfigurationException: Error parsing XML configuration at file:/home/user/workspaces/api2-grails/grails-app/conf/ehcacheCustom.xml
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:154)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:122)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:271)
... 46 common frames omitted
Caused by: org.ehcache.xml.exceptions.XmlConfigurationException: Error parsing XML configuration at file:/home/user/workspaces/api2-grails/grails-app/conf/ehcacheCustom.xml
at org.ehcache.xml.XmlConfiguration.<init>(XmlConfiguration.java:167)
at org.ehcache.xml.XmlConfiguration.<init>(XmlConfiguration.java:131)
at org.ehcache.xml.XmlConfiguration.<init>(XmlConfiguration.java:115)
at grails.plugin.cache.ehcache.DefaultXmlConfiguration.<init>(DefaultXmlConfiguration.groovy:22)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrConstructorNewInstance(ReflectiveInterceptor.java:1076)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:142)
... 48 common frames omitted
Caused by: org.xml.sax.SAXParseException: cvc-elt.1.a: Cannot find the declaration of element 'ehcache'.

thanks for any suggestions




Alex Snaps

unread,
Jul 3, 2018, 9:46:32 AM7/3/18
to ehcach...@googlegroups.com
Hey Heiko,
To your question, it looks like you're trying to use an ehcache 2.x XML file there... but you're using 3.0.0.m1. This won't work. 
Hence the `Cannot find the declaration of element 'ehcache'.`
Also, I'd use a newer version, or at least a stable one... 


--
You received this message because you are subscribed to the Google Groups "ehcache-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ehcache-user...@googlegroups.com.
To post to this group, send email to ehcach...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ehcache-users/4004b2c2-a281-41b2-a333-3bfc7c7f3e4d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Alex Snaps
Twitter: @alexsnaps

he...@raumo.de

unread,
Jul 3, 2018, 11:55:28 AM7/3/18
to ehcache-users
Hey Alex,
thanks for the fast reply. Well i guess there is no newer version of eh-cache for grails 3 out there (as u can see here: https://repo.grails.org/grails/core/org/grails/plugins/cache-ehcache/). Is an example ehcache.xml for version 3.0.0.M1 out there? these xml documentations are confusing me :/

Henri Tremblay

unread,
Jul 3, 2018, 11:58:12 AM7/3/18
to ehcach...@googlegroups.com
Have a look here: http://www.ehcache.org/documentation/3.5/xml.html

However, note that 3.0.0.m1 is pretty old. And beta.

Try 3.5. Hopefully it will work with grails. And we would like to know if it doesn't.

Henri

Louis Jacomet

unread,
Jul 4, 2018, 3:57:53 AM7/4/18
to ehcache-users
Hello,

There is a confusion around versions here. 3.0.0.M1 is the version of the Grails plugin.

It internally uses Ehcache 3.3.1.

And so while you should be able to upgrade to Ehcache 3.5, the most important thing is what Alex said first: have a look at the 3.x documentation as XML format is totally different.

Regards,
Louis

he...@raumo.de

unread,
Jul 4, 2018, 11:50:32 AM7/4/18
to ehcache-users
I tried 3.5.0. after dependency updates there was en error on start up:
2018-07-04 17:45:37.743  WARN --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsApplicationPostProcessor' defined in api2.Application: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [grails.boot.config.GrailsApplicationPostProcessor]: Factory method 'grailsApplicationPostProcessor' threw exception; nested exception is java.lang.NoClassDefFoundError: grails/plugin/cache/ehcache/EhcacheConfiguration
2018-07-04 17:45:37.752 ERROR --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Destroy method on bean with name 'org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory' threw an exception

so i guess there is a reason why the 3 year old 3.0.0.M1 is the "newest" ehcache version for grails. i don't know how other grails developers handle this

to the xml-file: i will create one these days and let u know if it worked with 3.0.0M1

Heiko

he...@raumo.de

unread,
Jul 4, 2018, 11:52:40 AM7/4/18
to ehcache-users
thx, i will look at it these days
Regards,
Heiko

Henri Tremblay

unread,
Jul 4, 2018, 12:22:50 PM7/4/18
to ehcach...@googlegroups.com
grails/plugin/cache/ehcache/EhcacheConfiguration is not Ehcache code. It is the grails plugin code. So it means the cache-ehcache is not in your classpath.

he...@raumo.de

unread,
Jul 5, 2018, 6:05:49 AM7/5/18
to ehcache-users
sooo, base on http://www.ehcache.org/documentation/3.5/xml.html i got somethin like this:

<?xml version="1.0" encoding="UTF-8"?>
<config
xsi:schemaLocation="ehcache-core.xsd">
    <cache alias="test">    
    </cache>
</config>

of course it wont work because its a pretty slim xml with no configuration (how for example do i configure TimeToLive?) This documentation says nothing about it and other important configurations. Is there a documentation in more detail out there? I couldn't find all the stuff i need in this documentation. Also an example xml with example cache nodes for different scenarios would be very helpful

Greetings
Heiko



Am Dienstag, 3. Juli 2018 17:58:12 UTC+2 schrieb Henri Tremblay:

Alex Snaps

unread,
Jul 5, 2018, 6:45:33 AM7/5/18
to ehcach...@googlegroups.com
It’s all in the doc and for a complete description, see the XSD itself:

 Plus the doc links to an example here:

`expiry` controls that. 


For more options, visit https://groups.google.com/d/optout.
--

Henri Tremblay

unread,
Jul 5, 2018, 9:24:23 AM7/5/18
to ehcach...@googlegroups.com
It's all in the doc. I suggest that you read it all.


he...@raumo.de

unread,
Jul 9, 2018, 6:55:17 AM7/9/18
to ehcache-users
Thx Alex & Henri,

my bad. u just read the link "XML Configuration" but obviously all other links belong to xml configuration aswell. no my caches work fine with primitive datatypes. I guess thats because of the default serialziers. For a custom pojo i need to write my own serialzier? 

Louis Jacomet

unread,
Jul 9, 2018, 8:54:33 AM7/9/18
to ehcache-users
That's correct - have a look at http://www.ehcache.org/documentation/3.5/serializers-copiers.html for the concepts and what's needed depending on your cache topology.

Regards,
Louis

Reply all
Reply to author
Forward
0 new messages