I ran into a problem that it is not possible to create a proxy for the bean. I use java, Spring. The code is below. I've been solving this issue for already several days and still have no idea what's wrong.
@SpringBootApplication
@EnableScheduling
@EnableCaching
@EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true)
public class ApiApplication {
public static void main(String[] args) {
SpringApplication.run(ApiApplication.class, args);
}
}
I call my service method from another service:
@Transactional
public void updateState(List<Long> ids, ResourceState state) {
ResourceService proxy = (ResourceService) AopContext.currentProxy();
proxy.updateStateBySystem(Lists.newArrayList(repository.findAllById(ids)), state);
}
I invoke this method in the same service:
@Async
@Transactional
public void purchaseForOrder(Order order) {
List<Resource> list = getResourcesForItem(order.getId(), null);
updateState(list.stream().map(ApplicationModel::getId).collect(Collectors.toList()), ResourceState.PURCHASING);
}
And I get the following error message:
Exception in thread "restartedMain" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: java.lang.IllegalStateException: Cannot find current proxy: Set 'exposeProxy' property on Advised to 'true' to make it available, and ensure that AopContext.currentProxy() is invoked in the same thread as the AOP invocation context.
at org.springframework.aop.framework.AopContext.currentProxy(AopContext.java:69)
at ru.sberbank.irpm.ApiApplication.main(ApiApplication.java:26)
... 5 more
Actually