【问题标题】:Spring 3.1.1 and Cache configuration issueSpring 3.1.1 和缓存配置问题
【发布时间】:2012-06-14 06:38:56
【问题描述】:

我正在测试 Spring 缓存,这是我的上下文文件

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    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">

    <cache:annotation-driven cache-manager="simpleCacheManager"/>

    <bean id="simpleCacheManager" class="org.springframework.cache.support.SimpleCacheManager">
        <property name="caches">
            <set>
                <bean class="org.springframework.cache.concurrent.ConcurrentCacheFactoryBean">
                    <property name="name" value="alfresco"/>
                </bean> 
                <bean class="org.springframework.cache.concurrent.ConcurrentCacheFactoryBean">
                    <property name="name" value="alfresco_article"/>
                </bean> 
                <bean class="org.springframework.cache.concurrent.ConcurrentCacheFactoryBean">
                    <property name="name" value="alfresco_action"/>
                </bean>
            </set>
        </property>
    </bean>

我添加了所有必需的库,但是我无法验证该库,因为 Eclipse 仍然告诉我缺少 AOPAlliance.jar 和 org.springframework.context-3.1.1.RELEASE.jar。

错误是:

在这一行发现了多个注释:找不到类 org.springframework.cache.concurrent.ConcurrentCacheFactoryBean。

已解决更改为 org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean

但是,调用 url 会发生这种情况:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [configuration-context.xml]; nested exception is java.lang.NoClassDefFoundError: org/springframework/aop/config/AopNamespaceUtils
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

root cause

org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [configuration-context.xml]; nested exception is java.lang.NoClassDefFoundError: org/springframework/aop/config/AopNamespaceUtils
    org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:412)

aop-alliance.jar 和 org.springframework.aop-3.1.1.RELEASE.jar 都在类路径中。

有什么线索吗?

谢谢,
安德烈亚

【问题讨论】:

    标签: java eclipse spring caching jakarta-ee


    【解决方案1】:

    再次检查 org.springframework.context-3.1.1.RELEASE.jar 确实在类路径中。 Eclipse 验证和这个问题的错误点。

    更新:我已经检查过了,你是对的。 ConcurrentCacheFactoryBean 似乎从 3.1.0.M1 开始被删除,并且可能在同一个包中被 ConcurrentMapCacheFactoryBean 取代。我还没有在发行说明中找到任何证据。但是,如果您将缓存的 bean 类名称更改为 ConcurrentMapCacheFactoryBean,它似乎工作正常。

    <bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean">
        <property name="name" value="alfresco"/>
    </bean> 
    

    UPDATE2:是的,确实ConcurrentCacheFactoryBean 已从renamed 变为ConcurrentMapCacheFactoryBean他们只是没有时间更新教程。

    【讨论】:

    • 是的,它可以工作,但仍然是 java.lang.ClassNotFoundException:org.springframework.aop.config.AopNamespaceUtils。有没有可能改变了其他东西?该类在类路径中可用
    • AopNamespaceUtils 应该在您的 spring-aop-3.1.1.RELEASE.jar 中 - 确保包含它。此外,这与缓存配置没有太大关系;-)
    • spring-aop 取决于 aopalliance-1.0.jar。确保你拥有它。
    猜你喜欢
    • 2012-04-09
    • 1970-01-01
    • 2018-07-31
    • 2020-04-21
    • 2014-10-18
    • 2016-04-23
    • 1970-01-01
    • 2011-05-15
    • 2020-03-04
    相关资源
    最近更新 更多