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