2017-09-14 163 views
0

我想使用Spring的緩存在露天,但緩存時我啓動tomcat我得到以下異常:春天在露天

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 14 in XML document from class path resource [alfresco/module/PolmanProject-alfresco-repo/context/service-context.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 8; cvc-elt.1.a: Cannot find the declaration of element 'beans'. 

我有以下模塊上下文:

?xml version='1.0' encoding='UTF-8'?> 
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'> 

<beans> 
... 
    <cache:annotation-driven /> 
    <bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager"> 
     <property name="caches"> 
      <set> 
       <bean 
      class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" 
        name="cacheService" /> 
      </set> 
     </property> 
    </bean> 
</beans> 

如果我刪除了bean和cacheManager,那麼我沒有得到這個異常。

我的上下文有什麼問題?

回答

1

你應該註釋行

<!-- <!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'> --> 

<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:cache="http://www.springframework.org/schema/cache" 
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd 
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd"> 

更換標記,這將解決您的問題。但是,有必要考慮使用緩存的另一個細節。本文解釋how to use the cache step by step

+0

這解決了我的問題。謝謝! – Kramer