2013-02-13 247 views
1

這一個看起來像一個簡單的問題。當我嘗試運行或編譯我的Maven項目在Eclipse中,我得到的錯誤:彈簧緩存配置

SEVERE: Servlet /articleservices threw load() exception 
org.xml.sax.SAXParseException; lineNumber: 73; columnNumber: 32; The prefix "p" for attribute "p:name" associated with an element type "bean" is not bound. 
    at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) 
    at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source) 
    at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) 
    at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source).. 

注意我截斷錯誤消息,因爲我相信這根是相當不言自明的。但是不管有多少我環顧四周,檢查,它似乎並不像有什麼毛病我的配置文件,主要內容如下:

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

    <context:component-scan base-package="mylittlecacheproject" /> 

    <mvc:resources mapping="/**" location="/" /> 

    <!-- Enables the Spring MVC @Controller programming model --> 
    <mvc:annotation-driven /> 

    <!-- annotation caching --> 
    <cache:annotation-driven /> 

    <!-- Enables aspjectj model --> 
    <aop:aspectj-autoproxy proxy-target-class="true" /> 

    <!-- Validator --> 
    <bean id="validator" 
     class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" /> 


    <!-- Resolve logical view names to .jsp resources in the /WEB-INF/views 
     directory --> 
    <bean 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="prefix" value="/WEB-INF/jsp/" /> 
     <property name="suffix" value=".jsp" /> 
     <property name="order" value="3" /> 
    </bean> 

    <!-- XMLConverter Injection --> 
    <bean id="XMLConverter" class="mppiwebservices.utils.xml.XMLConverter"> 
     <property name="marshaller" ref="castorMarshaller" /> 
     <property name="unmarshaller" ref="castorMarshaller" /> 
    </bean> 
    <bean id="castorMarshaller" class="org.springframework.oxm.castor.CastorMarshaller"> 
     <property name="mappingLocation" value="classpath:rssMapping.xml" /> 
     <property name="ignoreExtraElements" value="true" /> 
    </bean> 

    <!-- generic cache manager --> 
    <bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager"> 
     <property name="caches"> 
      <set> 
       <bean 
        class="org.springframework.cache.concurrent.ConcurrentCacheFactoryBean" 
        p:name="rsspassthrough" /> 
      </set> 
     </property> 
    </bean> 

</beans> 

好吧,我只是懶得夾出在項目中使用的其它豆類,但我的問題是...我真的指定春天的緩存正確的模式位置?或者我在這裏錯過了什麼?

回答

9

最後發現它時,彈簧文檔中,這個命名空間xmlns:p="http://www.springframework.org/schema/p"

是不包括在該示例配置。

0

您確定要在下面的代碼中寫p:name嗎?

<bean class="org.springframework.cache.concurrent.ConcurrentCacheFactoryBean" p:name="rsspassthrough" /> 
+0

以及[Spring文檔](http://static.springsource.org/spring/docs/3.1.0.M1/spring-framework-reference/html/cache.html)如何表達它。 我嘗試使用「名稱」而不是「p:name」,它引發了一個完全不同的錯誤。所以我不確定是否唯一有這個錯誤的人,Spring的模式沒有更新,或者我錯過了一些東西。 – 2013-02-14 03:08:32

+0

問題是,沒有爲'p'定義的名稱空間(類似於'mvc'或'aop')。您需要檢查名稱是屬性的所有模式。 – Garbage 2013-02-14 08:22:36