法@Cacheable(永远= TRUE)仍然被称为
问题描述:
我有这样的代码:法@Cacheable(永远= TRUE)仍然被称为
import com.jcabi.aspects.Cacheable;
@Cacheable(forever = true)
public String authorizedRequestBuilder() throws GeneralSecurityException, IOException {
return String.format("Bearer %s", acquireToken());
}
在调试时我看到了法的身体被称为几次。
有没有更多的配置要做?
答
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一起使用 –
你检查它是否达到'的String.format( “承载%S”,acquireToken())'呢?可能是代理服务器在后台使用,并且该方法调用仍然发生,但在代理缓存的代理服务器上。 – u6f6o
不知道我关注。整个方法应该被调用,因为注释不是?不管它的正文 –
@ EladBenda2是不是真的,只有在没有例外的情况下,结果才会被缓存。如果您的方法抛出异常,则没有任何要缓存的内容。另外,你确定你的二进制文件是编织的吗?请参阅http://aspects.jcabi.com/example-aspectj.html – yegor256