2016-06-21 34 views
8

我工作的緩存實現(exstremescale)Maven的多模塊項目,在那裏我已經添加下面的Maven依賴於緩存攔截器調用將被忽略

@Override 
@Cacheable(value = "productDetails", key = "#productId + #orgId") 
public Product productRead(final String productId, final String productKey, final String orgId, final CRApplicationEnum sourceSystem) throws IntegrationException { 

的cache

<dependency> 
     <groupId>com.ibm.extremescale</groupId> 
     <artifactId>ogclient</artifactId> 
     <version>8.6.0.20150901-215917</version> 
    </dependency> 

添加緩存註解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}" /> 

緩存僅適用於項目的一個maven模塊,我可以看到緩存攔截器調用,對於其餘的maven模塊,它忽略@cacheable註釋(它不會去攔截器)。

我們沒有PostConstructorSelf invokation

我們正在使用Atomikos公司的事務管理器和將來到高速緩存方法前執行CXF -interceptors。

請幫我在這

+0

在模塊上工作,而不是其他人有點奇怪我會說。 Spring應用程序上下文不關心你的類從哪裏加載。你正在使用父/子上下文嗎? –

+0

在調試時我們知道,由JdkDynamicAopProxy類爲具有可緩存註釋的bean準備的攔截器列表沒有將緩存攔截器添加到列表中。 –

+0

你可以分享一個樣本,這會容易得多。你可以顯示該bean的bean配置嗎?你有沒有機會展示一個界面? –

回答

0

您對JdkDynamixAopProxy評論和查看代碼讓我覺得,你已經與@Cacheable註釋的方法是在一個具體的類。對於具體類的註釋來表現正確的行爲;您需要在應用程序中啓用cglib代理。

這可以通過將代理目標類參數添加到緩存註釋驅動標籤來完成。

<cache:annotation-driven proxy-target-class="true"/>

如果你不想啓用基於代理類爲整個應用程序;

@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)

0

調用在同一個類中的方法繞過動態代理和任何橫切關注點比如緩存,交易等,這是部分:您可以通過這個註釋來註釋它指定一個特定類的行爲動態代理邏輯也被繞過。那麼你的問題可能是Spring cache @Cacheable method ignored when called from within the same class

如果是這樣,修復方法是使用AspectJ編譯時或加載時編織。