Sun*_* Rk 8 java spring caching spring-cache
我正在为maven多模块项目开发缓存实现(exstremescale),我在其中添加了maven依赖项
<dependency>
<groupId>com.ibm.extremescale</groupId>
<artifactId>ogclient</artifactId>
<version>8.6.0.20150901-215917</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
添加了缓存注释
@Override
@Cacheable(value = "productDetails", key = "#productId + #orgId")
public Product productRead(final String productId, final String productKey, final String orgId, final CRApplicationEnum sourceSystem) throws IntegrationException {
Run Code Online (Sandbox Code Playgroud)
缓存manager.xml
<?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:p="http://www.springframework.org/schema/p"
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 />
<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager" primary="true">
<property name="caches">
<set>
<bean class="com.ibm.websphere.objectgrid.spring.ObjectGridCache"
p:name="eventDetails" p:map-name="${iev.eventDetails.mapName}"
p:object-grid-client-ref="wxsGridClient" />
<bean class="com.ibm.websphere.objectgrid.spring.ObjectGridCache"
p:name="eventValidationDetails" p:map-name="${iev.eventValidationDetails.mapName}"
p:object-grid-client-ref="wxsGridClient" />
<bean class="com.ibm.websphere.objectgrid.spring.ObjectGridCache"
p:name="productDetails" p:map-name="${ipr.productDetails.mapName}"
p:object-grid-client-ref="wxsGridClient" />
</set>
</property>
</bean>
<bean id="wxsCSDomain"
class="com.ibm.websphere.objectgrid.spring.ObjectGridCatalogServiceDomainBean"
p:catalog-service-endpoints="${xscale.catalogServiceEndpoint}" />
<bean id="wxsGridClient"
class="com.ibm.websphere.objectgrid.spring.ObjectGridClientBean"
p:catalog-service-domain-ref="wxsCSDomain" p:objectGridName="${wxs.objectGridName}" />
Run Code Online (Sandbox Code Playgroud)
缓存仅适用于项目的一个maven模块,我可以看到缓存拦截器调用,对于maven模块的其余部分,它忽略了@cacheable注释(它不会进入拦截器).
我们没有PostConstructor或Self invokation
我们使用atomikos作为事务管理器和CXF -interceptors,它们将在进入缓存方法之前执行.
请帮帮我
小智 0
您对 JdkDynamixAopProxy 的评论以及查看代码让我认为您注释的方法@Cacheable是在一个具体的类中。并让具体类上的注释表现出正确的行为;您需要在应用程序中启用 cglib 代理。
这可以通过将代理目标类参数添加到缓存注释驱动标记来完成。
<cache:annotation-driven proxy-target-class="true"/>
如果您不想为整个应用程序启用基于类的代理;您可以通过使用以下注释来指定特定类的行为:
@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)