Spring Cache配置

时间:2013-02-13 07:50:00

标签: spring caching

这个似乎是一个简单的问题。当我尝试在eclipse中运行或编译我的maven项目时,我收到错误:

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>

好吧,我只是懒得剪掉项目中使用的其他bean,但我的问题是......我实际上是为spring的缓存指定了正确的架构位置吗?或者我在这里遗漏了什么?

2 个答案:

答案 0 :(得分:9)

最后在spring文档中找到了这个名称空间xmlns:p="http://www.springframework.org/schema/p"

未包含在示例配置中。

答案 1 :(得分:0)

您确定要在以下代码中编写p:name吗?

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