将 ehcache:proxy 迁移到 spring 4

Migrate ehcache:proxy to spring 4

我正在将应用程序从 Jboss 4.2.2 / java 6 / Spring 2.5.4 升级到 Wildfly 9.0.2 / java 8 / Spring 4.3.2。

Spring/Ehcache 对其界面和工作流程进行了很多更改,我无法找到任何信息来说明为什么我的 xml 不再正确。

我遇到问题的声明:

<ehcache:proxy id="itemDaoCacheProxy" refId="itemDao">
    <ehcache:caching methodName="getAllItemNo" cacheName="itemTableCache" />
</ehcache:proxy>

错误信息:

Context initialization failed: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 98 in XML document from ServletContext resource [/WEB-INF/spring-cfg.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 98; columnNumber: 54; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'cache:proxy'.

我的 xml 声明如下所示:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xmlns:cache="http://www.springframework.org/schema/cache"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
        http://www.springframework.org/schema/cache 
        http://www.springframework.org/schema/cache/spring-cache.xsd"> 

我正在使用 spring-context-support.jar 作为 chache 实用程序,但问题似乎与 xml 文件和架构无关。 "proxy" 元素似乎在后来的版本中消失了。

旧:

https://github.com/zznate/spring-modules-ehcache/blob/master/src/main/java/org/springmodules/cache/config/ehcache/springmodules-ehcache.xsd

新:

http://www.springframework.org/schema/cache/spring-cache.xsd

ehcache:proxy 究竟做了什么?我如何将其迁移到新标准?

此致,

这篇post详细介绍了我迁移系统的方法。

http://springtips.blogspot.se/2007/06/caching-methods-result-using-spring-and_23.html

<bean id="itemDaoCacheProxyMethodCache" class="org.springframework.aop.support.NameMatchMethodPointcutAdvisor">
    <property name="advice">
        <bean id="methodCacheInterceptor" class="com.myproject.mymodule.MethodCacheInterceptor">
            <property name="cache">
                <bean id="methodCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
                    <property name="cacheManager">
                        <ref bean="ehcache"/>
                    </property>
                    <property name="cacheName">
                        <value>itemTableCache</value>
                    </property>
                </bean>
            </property>
        </bean>
    </property>
    <property name="mappedName" value="getAllItemNo"/>
</bean>

<bean id="itemDaoCacheProxy" class="org.springframework.aop.framework.ProxyFactoryBean">
    <property name="target" ref="itemDao"/>
    <property name="interceptorNames">
        <list>
            <value>itemDaoCacheProxyMethodCache</value>
        </list>
    </property>
</bean>

代码的作用是创建一个新容器来包装我的 class 并为指定函数实现缓存功能。

这意味着可以有 class 的实例,其中一些是 checking/updating 缓存的响应,而另一些不是。