1

这似乎是一个简单的问题。当我尝试在 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 的缓存指定了正确的模式位置?或者我在这里错过了什么?

4

2 回答 2

9

终于找到了,在spring文档中,这个namespacexmlns:p="http://www.springframework.org/schema/p"

未包含在示例配置中。

于 2013-02-15T04:29:32.613 回答
0

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

<bean class="org.springframework.cache.concurrent.ConcurrentCacheFactoryBean" p:name="rsspassthrough" />
于 2013-02-13T13:43:47.697 回答