Did you know? DZone has great portals for Python, Cloud, NoSQL, and HTML5!

Lives in the UK. Likes blogging, cycling and eating lemon drizzle cake. Roger is a DZone MVB and is not an employee of DZone and has posted 60 posts at DZone. View Full User Profile

Spring 3 and Apache Commons JCS Exception

January 27, 2012 AT 12:09 AM
  • submit to reddit

I’ve seen a couple of projects in the last few months that have needed to cache data between requests. The developers, not wanting to write their own caching module, decided that Apache Commons JCS fitted the bill and added it to their Maven POM using the latest version:

<dependency>
    <groupId>jcs</groupId>
    <artifactId>jcs</artifactId>
    <version>1.3</version>
</dependency>  

Unfortunately, when the build ran, exceptions with the following key root causes:

Caused by: javax.xml.parsers.ParserConfigurationException: Unable to validate using XSD: 
Your JAXP provider [org.apache.xerces.jaxp.DocumentBuilderFactoryImpl@8034b6] does not support XML Schema. 
Are you running on Java 1.4 with Apache Crimson? Upgrade to Apache Xerces (or Java 1.5) for full XSD support.

Caused by: java.lang.IllegalArgumentException: No attributes are implemented

...began to appear similar to those shown in the example below:

Tests run: 5, Failures: 0, Errors: 4, Skipped: 1, Time elapsed: 0.303 sec <<< FAILURE!
testSendFileStringOutputStream(com.configureconnect.cplayer.ImageGeneratorServiceTest)  Time elapsed: 0.105 sec  <<< ERROR!
org.unitils.core.UnitilsException: Unable to create application context for locations [test-beans.xml]
 at org.unitils.spring.util.ApplicationContextManager.createInstanceForValues(ApplicationContextManager.java:121)
 at org.unitils.spring.util.ApplicationContextManager.createInstanceForValues(ApplicationContextManager.java:36)
 at org.unitils.core.util.AnnotatedInstanceManager.getInstanceImpl(AnnotatedInstanceManager.java:234)
 at org.unitils.core.util.AnnotatedInstanceManager.getInstance(AnnotatedInstanceManager.java:121)
 at org.unitils.spring.util.ApplicationContextManager.getApplicationContext(ApplicationContextManager.java:65)
 at org.unitils.spring.SpringModule.getApplicationContext(SpringModule.java:222)
 at org.unitils.spring.SpringModule$1.isApplicableFor(SpringModule.java:104)
 at 

---- Lots of lines removed for readability....

 at org.apache.maven.surefire.Surefire.run(Surefire.java:169)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:592)
 at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:350)
 at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1021)
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Parser configuration exception parsing XML from class path resource [test-beans.xml]; nested exception is javax.xml.parsers.ParserConfigurationException: Unable to validate using XSD: Your JAXP provider [org.apache.xerces.jaxp.DocumentBuilderFactoryImpl@8034b6] does not support XML Schema. Are you running on Java 1.4 with Apache Crimson? Upgrade to Apache Xerces (or Java 1.5) for full XSD support.
 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:404)
 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
 at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
 at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
 at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
 at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:212)
 at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:126)
 at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:92)
 at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
 at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:467)
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:397)
 at org.unitils.spring.util.ApplicationContextManager.createInstanceForValues(ApplicationContextManager.java:117)
 ... 32 more
Caused by: javax.xml.parsers.ParserConfigurationException: Unable to validate using XSD: Your JAXP provider [org.apache.xerces.jaxp.DocumentBuilderFactoryImpl@8034b6] does not support XML Schema. Are you running on Java 1.4 with Apache Crimson? Upgrade to Apache Xerces (or Java 1.5) for full XSD support.
 at org.springframework.beans.factory.xml.DefaultDocumentLoader.createDocumentBuilderFactory(DefaultDocumentLoader.java:102)
 at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:70)
 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:388)
 ... 44 more
Caused by: java.lang.IllegalArgumentException: No attributes are implemented
 at org.apache.xerces.jaxp.DocumentBuilderFactoryImpl.setAttribute(DocumentBuilderFactoryImpl.java:98)
 at org.springframework.beans.factory.xml.DefaultDocumentLoader.createDocumentBuilderFactory(DefaultDocumentLoader.java:99)
 ... 46 more

From the stack trace, I believe that it was JCS’s dependency on xerces and other XML APIs that have caused the problem.


The classes from these libraries have been added to the Java SE SDK and improved upon, whilst xerces has also continued to grow, change and diverge. Hence, when compiling with Java 5 and greater, the xerces classes conflict with Java SE SDK creating the exception demonstrated above.

Possible Solutions

  • Don’t use JCS: this works!
  • Try excluding xerces using Maven. I haven’t tried this yet...
  • Upgrade to Spring 3.1

The version of Spring used was 3.0.5, but the Guys at Spring have been busy and recently released Spring 3.1, which comes with its own cache. I haven’t looked at this yet, but it’s worth investigating...

 

From http://www.captaindebug.com/2012/01/spring-3-and-apache-commons-jcs.html

Comments

Dapeng Liu replied on Fri, 2012/01/27 - 4:49am

depends on your needs, if clustering is not needed, a plain old ConcurrentHashMap should be sufficient for most of the need if TTL is needed, then start a background Thread to periodically wakeup and do some cleanup this approach works quite well for me so far no dependency hell, smaller war file, simple code, all win situation

Amir Pashazadeh replied on Sat, 2012/01/28 - 1:14pm

Spring 3.1 does not have a cache provider, it just provides a Cache abstraction layer over some Cache implementations (just like most of Spring abstractions). It just simplifies using caches (by annotating methods), but you must have a supported cache implementation ready.

 As far as I remember EhCache is one of the supported ones.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.