Question

I have an application using Spring and Ehcache. Each time I start the application from Eclipse, it runs fine. But when I build it from Maven and run it on the server, I keep having this error:

    INFO  XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [spring.xml]
    Exception in thread "main"     org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 29 in XML document from class path
resource [spring.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 29; columnNumber: 71; cvc-complex-type.2.
4.c: The matching wildcard is strict, but no declaration can be found for element 'ehcache:annotation-driven'.
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:398)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:335)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:216)
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:187)
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:251)
        at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
        at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
        at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
        at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:540)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:454)
        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
        at com.natixis.etp.data.rmi.DataServer.main_aroundBody0(DataServer.java:145)
        at com.natixis.etp.data.rmi.DataServer.main(DataServer.java:45)
Caused by: org.xml.sax.SAXParseException; lineNumber: 29; columnNumber: 71; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'ehcache:annotation-driven'.
        at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
        at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
        at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:76)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadDocument(XmlBeanDefinitionReader.java:428)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)

The ehcache:annotation-driven definition exists in ehcache-spring-1.2.xsd.
I have read the several related issues about it, I applied what was adviced and so far I have no luck. I don't and can't use the Maven shader plugin because of our environment specifics, and I don't think it would help because I checked and rechecked the schema handlers in the dependencies.

I wanted to know if you have any clue. Here is my spring file:

        <?xml version="1.0" encoding="UTF-8"?>
        <beans xmlns="http://www.springframework.org/schema/beans"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
            xmlns:context="http://www.springframework.org/schema/context"
            xmlns:tx="http://www.springframework.org/schema/tx" 
            xmlns:aop="http://www.springframework.org/schema/aop"
            xmlns:ehcache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring"
            xsi:schemaLocation="
            http://www.springframework.org/schema/beans 
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            classpath:spring-beans-3.0.xsd 
            http://www.springframework.org/schema/aop 
            http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
            classpath:spring-aop-3.0.xsd
            http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context-3.2.xsd
            classpath:spring-context.xsd
            http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring
            http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.2.xsd
            classpath:ehcache-spring-1.2.xsd
            ">

            <context:annotation-config />
            <context:spring-configured />

            [...]

            <ehcache:annotation-driven mode="aspectj"
                cache-manager="cacheManager" self-populating-cache-scope="shared" />

            <aop:aspectj-autoproxy>
                <aop:include name="traceInvocation" />
                <!-- aop:include name="performanceMonitor" / -->
                <aop:include name="ehCacheInvocation" />
            </aop:aspectj-autoproxy>

            <ehcache:config cache-manager="cacheManager">
                <ehcache:evict-expired-elements
                    interval="60" />
            </ehcache:config>

            <bean id="cacheManager"
                class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
                <property name="configLocation" value="META-INF/ehcache.xml" />
                <property name="shared" value="true" />
            </bean>
            [...]
        </beans> 

As you see, I added the classpath entries because I had conflicts with schema handlers within the Spring aop schema handler. I have checked the content of ehcache-aspectj-annotations-1.2.0.jar.dir/META-INF/spring.schemas:

http\://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.0.xsd=com/googlecode/ehcache/annotations/ehcache-spring-1.0.xsd
http\://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.1.xsd=com/googlecode/ehcache/annotations/ehcache-spring-1.1.xsd
http\://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.2.xsd=com/googlecode/ehcache/annotations/ehcache-spring-1.2.xsd

It seems fine to me.

Here are my main dependencies by the way:

    <dependencies>
    [...]
        <dependency>
            <groupId>aopalliance</groupId>
            <artifactId>aopalliance</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>xerces</groupId>
            <artifactId>xercesImpl</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
        </dependency>
        <dependency>
            <groupId>net.sf.ehcache</groupId>
            <artifactId>ehcache-core</artifactId>
            <version>2.4.1</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>**************</groupId>
            <artifactId>ehcache-aspectj-annotations</artifactId>
            <version>1.2.0</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>${aspectj.version}</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>${aspectj.version}</version>
        </dependency>

        <dependency>
          <groupId>com.googlecode.ehcache-spring-annotations</groupId>
          <artifactId>ehcache-spring-annotations</artifactId>
          <version>1.2.0</version>
        </dependency>
    </dependencies>
Was it helpful?

Solution

Ok, I haven't been able to find the root cause of the issue but I tried to use the Spring bean source code in order to trace the calls leading to this issue. It appeared that the version of Spring beans I was using (4.0.2-RELEASE) had references to Java 8 classes although my project is under Java 7.

I am not sure if it was the problem because I would expect a clear error message, but anyway, I roll-backed to a Java 7 compliant version of spring beans (3.2.8.RELEASE) and the issue disappeared. It works fine now even though it's a bit frustrating.

OTHER TIPS

I had a similar issue and wanted to add some details, in case others are searching. The error:

nested exception is org.xml.sax.SAXParseException; lineNumber: 29; columnNumber: 71; cvc-complex-type.2. 4.c: The matching wildcard is strict, but no declaration can be found for element 'ehcache:annotation-driven'.

Means it can't find what ehcache:annotation-driven means. This is because the xsd files at the uri is no longer hosted. I found an archived version of the file and put it in the same directory then was able to reference the xsd by relative path.

For more details, you can read the related questions/answers: How to Configure Eclipse to Work with `ehcache` , How to Reference Local XSD File By Relative Path , and Context.xml's References .

Your XML parser is attempting to validate against your linked schema location/s - and the 'annotation-driven' tag doesn't appear in the schema provided. Unfortunately I've gotten this error before (intermittently as well), maybe this indicates the remote location is temporary down (you would hope for a more explicit error message through)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top