Announcement Announcement Module
Collapse
No announcement yet.
Renamed "ehcache.xml" to "my.xml"-Cannot find the declaration of element 'ehcache' Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Renamed "ehcache.xml" to "my.xml"-Cannot find the declaration of element 'ehcache'

    Using ehcache1.5 and Spring 2.5.

    The code works successfully, as long as I keep the name of the XML as default "ehcache.xml". I can load it using code:
    Code:
    CacheManager.create()
    However, if I change the name of "ehcache.xml" to something like "my.xml", I get exception. I load the "my.xml" as:

    Code:
    URL urlOfCoreCacheXML = getClass().getResource("/my.xml");
    singletonCacheManager = CacheManager.create(urlOfCoreCacheXML);
    The "my.xml" is in the src folder of the project (renamed from "ehcache.xml").

    I also get the path to my.xml using property in a Spring bean as:
    Code:
    core.ehcache.file=/core-ehcache.xml
    If I change name to "my.xml", I get error as below, when it reads "my.xml" from src directory:

    Code:
    org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 1 in XML document from file [C:\workspace-\bin\my.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'ehcache'.
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:404)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
    	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.test.AbstractSingleSpringContextTests.createApplicationContext(AbstractSingleSpringContextTests.java:212)
    	at org.springframework.test.AbstractSingleSpringContextTests.loadContextLocations(AbstractSingleSpringContextTests.java:189)
    	at org.springframework.test.AbstractSingleSpringContextTests.loadContext(AbstractSingleSpringContextTests.java:169)
    	at org.springframework.test.AbstractSpringContextTests.getContext(AbstractSpringContextTests.java:140)
    	at org.springframework.test.AbstractSingleSpringContextTests.setUp(AbstractSingleSpringContextTests.java:98)
    	at junit.framework.TestCase.runBare(TestCase.java:125)
    	at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:76)
    	at junit.framework.TestResult$1.protect(TestResult.java:106)
    	at junit.framework.TestResult.runProtected(TestResult.java:124)
    	at junit.framework.TestResult.run(TestResult.java:109)
    	at junit.framework.TestCase.run(TestCase.java:118)
    	at junit.framework.TestSuite.runTest(TestSuite.java:208)
    	at junit.framework.TestSuite.run(TestSuite.java:203)
    	at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
    	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
    Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'ehcache'.
    	at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
    	at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
    	at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
    	at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
    	at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
    	at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown Source)
    	at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
    	at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)
    	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    	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:75)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)
    	... 25 more
    "my.xml" is as:

    Code:
    <ehcache>
    
    	<defaultCache
     
    		maxElementsInMemory="10000"
    		eternal="false"
    		timeToIdleSeconds="1000"
    		timeToLiveSeconds="1000"
    		overflowToDisk="true"
    		diskPersistent="false"
    		diskExpiryThreadIntervalSeconds="120" 
    	/>    
    
     
      	<cache name="cache1"
                  maxElementsInMemory="10000"
                  eternal="false"
                  timeToIdleSeconds="1800"
                  timeToLiveSeconds="1800"
                  overflowToDisk="false">
    
        </cache>
        
    
        <cache name="cache2"
                  maxElementsInMemory="10000"
                  eternal="false"
                  timeToIdleSeconds="60"
                  timeToLiveSeconds="60"
                  overflowToDisk="false">
                  
    
        </cache>
        
    </ehcache>
    As soon as I change the name of the "my.xml" to "ehcache.xml", the code works. As far as I can see, "my.xml" is well-formed. According to documentation of ehcache, the name of "defaultcache.xml" can be changed and it can be loaded either using URL API, or File API.

    In this case, it can see the "my.xml" file in the classpath.

    I get above exception when the console states:

    Code:
    INFO: Loading XML bean definitions from file [C:\workspace\bin\my.xml]
    Any suggestion will be appreciated.
    Last edited by sunfun; May 21st, 2010, 01:58 PM.

  • #2
    The error is because the Spring test case support is trying to load the file my.xml as part of your application context.
    You need to fix the configuration of your Spring test cases to not include this file an application context definition.

    If you're not sure where to go, you need to look at the specific test case and how it defines the context locations, which are then used from your stack trace via
    Code:
    ...
    org.springframework.test.AbstractSingleSpringContextTests.loadContextLocations(AbstractSingleSpringContextTests.java:189)
    ...
    I assume that in your project the test is configured so that it loads xml files in a particular directory but excludes ehcache.xml.

    Comment

    Working...
    X