schema_reference.4: Failed to read schema document 'http://ehcache.org/ehcache.xsd'

3,724 views
Skip to first unread message

Ralph

unread,
Aug 18, 2010, 8:48:43 AM8/18/10
to Ehcache Spring Annotations
Hi all,

I hope you can help me with my problem. I just can't see what I'm
doing wrong. I would like to use caching in my Spring web application.

I adjusted my applicationContext.xml and added:

<ehcache:annotation-driven />
<bean id="cacheManager"
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"/>

I also created ehcache.xml:

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
updateCheck="false">
<!--
| Please see http://ehcache.sourceforge.net/documentation/configuration.html
for
| detailed information on how to configurigure caches in this
file
+-->
<!-- Location of persistent caches on disk -->
<diskStore path="java.io.tmpdir/
EhCacheSpringAnnotationsExampleApp" />

<defaultCache eternal="false" maxElementsInMemory="1000"
overflowToDisk="false" diskPersistent="false"
timeToIdleSeconds="0"
timeToLiveSeconds="600" memoryStoreEvictionPolicy="LRU"/>

<cache name="weatherCache" eternal="false"
maxElementsInMemory="100" overflowToDisk="false"
diskPersistent="false"
timeToIdleSeconds="0" timeToLiveSeconds="300"
memoryStoreEvictionPolicy="LRU" />

<cache name="locationSearchCache" eternal="false"
maxElementsInMemory="100" overflowToDisk="false"
diskPersistent="false"
timeToIdleSeconds="0" timeToLiveSeconds="300"
memoryStoreEvictionPolicy="LRU" />
</ehcache>


When I run my project, it stops for a moment when it tries to read
ehcache.xml and then gives the error:

org.xml.sax.SAXParseException: schema_reference.4: Failed to read
schema document 'http://ehcache.org/ehcache.xsd', because 1) could not
find the document; 2) the document could not be read; 3) the root
element of the document is not <xsd:schema>.

and also:

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:
Line 3 in XML document from ServletContext resource [/WEB-INF/
ehcache.xml] is invalid; nested exception is
org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration
of element 'ehcache'.

Does anybody get the same problem or can you help me solving this
problem?

Thank you!
Ralph

Eric Dalquist

unread,
Aug 18, 2010, 10:30:44 AM8/18/10
to ehcache-sprin...@googlegroups.com
Can you access http://ehcache.org/ehcache.xsd from your computer?

If not the schema declaration isn't required in the ehcache.xml config. Try just changing:

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd" updateCheck="false">
to
<ehcache updateCheck="false">

Ralph

unread,
Aug 18, 2010, 10:59:32 AM8/18/10
to Ehcache Spring Annotations
Hi,

thank you for your quick reply. I still get an error:
org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration
of element 'ehcache'.

Actually I'm not sure that I have the correct setup. I'm not sure how
to link my ehcache.xml in my project.

It's in my web.xml and looks like:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://
java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://
java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>FLLims</display-name>
<description>FLLims application</description>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/ehcache.xml /WEB-INF/applicationContext-
jdbc.xml /WEB-INF/applicationContext.xml
/WEB-INF/applicationContext-security.xml</param-value>
</context-param>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>
org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-
class>org.springframework.web.context.ContextLoaderListener</listener-
class>
</listener>
<servlet>
<servlet-name>FLLims</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</
servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>FLLims</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>FLLims</servlet-name>
<url-pattern>*.xls</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

If I remove /WEB-INF/ehcache.xml from my web.xml file, I get an error
saying Unable to find projectCache (which I defined in my dao as
@Cacheable(cacheName = "projectCache")
I guess because the application doesn't know of the ehcache.xml file.

Shouldn't I have something like this in my applicationContext:
<ehcache:annotation-driven cache-manager="cacheManager"/>
<bean id="cacheManager"
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:/WEB-INF/
ehcache.xml"/>
</bean>

I'm really confused :-) Well, it's the end of the day here, so maybe
that's why.

Thank you!
Ralph


On 18 aug, 16:30, Eric Dalquist <eric.dalqu...@gmail.com> wrote:
> Can you accesshttp://ehcache.org/ehcache.xsdfrom your computer?
>
> If not the schema declaration isn't required in the ehcache.xml config. Try
> just changing:
> <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
> updateCheck="false">
> to
> <ehcache updateCheck="false">
>

Eric Dalquist

unread,
Aug 18, 2010, 11:07:49 AM8/18/10
to ehcache-sprin...@googlegroups.com
ehcache.xml is not a spring configuration file. It is the Ehcache configuration file and needs to reside in WEB-INF/classes or you need to specify its location.

Your example spring config snippet is close:

<ehcache:annotation-driven cache-manager="cacheManager"/>
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
      <property name="configLocation" value="classpath:/WEB-INF/ehcache.xml"/>
</bean>

The problem is /WEB-INF/ehcache.xml is not part of a web applications classpath. Only files under WEB-INF/classes are in the classpath as well as the jars in WEB-INF/lib. Simply moving ehcache.xml to WEB-INF/classes/ehcache.xml and using the following spring configuration should work


<ehcache:annotation-driven cache-manager="cacheManager"/>
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" />

Ralph

unread,
Aug 19, 2010, 5:20:36 AM8/19/10
to Ehcache Spring Annotations
Of course! That did the trick! Thanks a lot!

Cheers
Ralph

On 18 aug, 17:07, Eric Dalquist <eric.dalqu...@gmail.com> wrote:
> ehcache.xml is *not* a spring configuration file. It is the Ehcache
> configuration file and needs to reside in WEB-INF/classes or you need to
> specify its location.
>
> Your example spring config snippet is close:
> <ehcache:annotation-driven cache-manager="cacheManager"/>
> <bean id="cacheManager"
> class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
>       <property name="configLocation"
> value="classpath:/WEB-INF/ehcache.xml"/>
> </bean>
>
> The problem is /WEB-INF/ehcache.xml is not part of a web applications
> classpath. Only files under WEB-INF/classes are in the classpath as well as
> the jars in WEB-INF/lib. Simply moving ehcache.xml to
> WEB-INF/classes/ehcache.xml and using the following spring configuration
> should work
>
> <ehcache:annotation-driven cache-manager="cacheManager"/>
> <bean id="cacheManager"
> class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" />
>
> > > Can you accesshttp://ehcache.org/ehcache.xsdfromyour computer?
Reply all
Reply to author
Forward
0 new messages