SpringBoot:3.0.1 + Java17 + starter-cache + starter-data-redis
@EnableAspectJAutoProxy(exposeProxy = true, proxyTargetClass = true)
@EnableCaching
public class StartupApplication { }
@Service
public class AccountService {
@Cacheable(cacheNames = "accountsActivated", sync = true)
public List retrieveActivatedCacheable() { }
public AccountDto retrieveActivatedByName(String name) {
// 这里 call retrieveActivatedCacheable() 不会从缓存中查询
}
[ol]
aopContext.getCurrentProxy
((AccountService) AopContext.currentProxy()).retrieveActivatedCacheable()
[/ol]
[ol]
两个方法放不同类
[/ol]
[ol]
[/ol]
@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)
public class AccountService
@Autowired
private AccountService self;
@Cacheable(cacheNames = "accountsActivated", sync = true)
public List retrieveActivatedCacheable() { }
public AccountDto retrieveActivatedByName(String name) {
self.retrieveActivatedCacheable().....
java.lang.ClassCastException: class java.util.LinkedHashMap cannot be cast to class demo.usul.dto.AccountDto (java.util.LinkedHashMap is in module java.base of loader 'bootstrap'; demo.usul.dto.AccountDto is in unnamed module of loader org.springframework.boot.devtools.restart.classloader.RestartClassLoader @5d339696)
--add-opens=java.base/java.time=ALL-UNNAMED
--add-opens=java.base/java.lang=ALL-UNNAMED
--add-opens=java.base/java.util=ALL-UNNAMED
load-time weaver 使用 spring 提供的 LTW, 不需要引入 aspectj 的 weaver ,貌似是最推荐的方案, spring 原生 LTW
其余不变,vm 参数加上 -javaagent:/path/to/spring-instrument-6.0.13.jar
如果换成 -javaagent:/path/to/aspectjweaver-1.9.19.jar
weaver, accountdto, public, Java