2016-09-14 108 views
2

我有這樣的代碼:法@Cacheable(永遠= TRUE)仍然被稱爲

import com.jcabi.aspects.Cacheable; 

@Cacheable(forever = true) 
public String authorizedRequestBuilder() throws GeneralSecurityException, IOException { 
    return String.format("Bearer %s", acquireToken()); 
} 

在調試時我看到了法的身體被稱爲幾次。

有沒有更多的配置要做?

+0

你檢查它是否達到'的String.format( 「承載%S」,acquireToken())'呢?可能是代理服務器在後臺使用,並且該方法調用仍然發生,但在代理緩存的代理服務器上。 – u6f6o

+0

不知道我關注。整個方法應該被調用,因爲註釋不是?不管它的正文 –

+0

@ EladBenda2是不是真的,只有在沒有例外的情況下,結果纔會被緩存。如果您的方法拋出異常,則沒有任何要緩存的內容。另外,你確定你的二進制文件是編織的嗎?請參閱http://aspects.jcabi.com/example-aspectj.html – yegor256

回答

0

jcabionly works with AspectJ compile time weaving.

所以,你確信你使用的是AspectJ的編譯器來編譯您的代碼?按照this blog post,你應該使用jcabi Maven插件(或同等學歷):

<project> 
    <dependencies> 
    <dependency> 
     <groupId>com.jcabi</groupId> 
     <artifactId>jcabi-aspects</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.aspectj</groupId> 
     <artifactId>aspectjrt</artifactId> 
    </dependency> 
    </dependencies> 
    <build> 
    <plugins> 
     <plugin> 
     <groupId>com.jcabi</groupId> 
     <artifactId>jcabi-maven-plugin</artifactId> 
     <executions> 
      <execution> 
      <goals> 
       <goal>ajc</goal> 
      </goals> 
      </execution> 
     </executions> 
     </plugin> 
    </plugins> 
    </build> 
</project> 
+0

這是真的,它只能與AspectJ一起使用 –

相關問題