java - 迁移ehcache :proxy to spring 4

标签 java spring xsd ehcache xsd-validation

我正在将应用程序从 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 文件和模式无关。 “代理”元素似乎在后来的版本中消失了。

旧:

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 到底做了什么以及如何将其迁移到新标准?

最诚挚的问候,

最佳答案

这篇文章详细介绍了我用来迁移系统的方法。

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>

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

这意味着该类的实例中可能有一些正在检查/更新缓存的响应,而有些则没有。

关于java - 迁移ehcache :proxy to spring 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39724399/

相关文章:

java - Jackson - 处理多种类型的 JSON

java - Spring ThreadPoolTask​​Executor 的线程计数始终为 1

java - Spring Boot 应用程序中的 MySQL 数据库中没有创建表

java - 指标报告定制

java - 用 Java 玩变音?

java - 如何在Spring Rest Request中访问内部json对象

xml - 您可以转换无序的 xml 以匹配 xsd :sequence order?

C# 代码(为 xsd 架构中具有 decimal 和 int 的选择元素生成)不包含枚举

c# - xs :key, 为什么当键值不是键引用的成员时验证通过?

java - Android 动画 - 不允许使用字符串类型