進行批量數據更新的時候, 爲了接口主線程的直接返回避免http超時, 新構建Thread進行數據的更新.
爲了避免更新中出現問題導致最終的數據庫不一致, 添加了事務.
由於在一個類內操作, 於是添加了
@EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true) 註解,
同時在調用的時候, 使用 AopContext.currentProxy() 獲取當前的代理類, 測試報錯如下:
Cannot find current proxy: Set 'exposeProxy' property on Advised to 'true' to make it
常見錯誤, 但是明明已經在類上進行了聲明.
後發現是Thread的問題,導致聲明式事務無法使用, 解決方案多是回到了顯式調用, 如:
https://blog.csdn.net/weixin_33728268/article/details/92718629
但是這種調用徒增了很多的模板代碼,後考慮設置屬性 localProxy, 利用@PostConstruct, 使用獲取當前類的對象,
@Autowired ApplicationContext context;
localProxy = context.getBean(當前類.class); 獲取的localProxy 默認爲代理對象, 後續的調用直接使用localProxy調用即可.