ApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
AsyncBean session = ctx.getBean(AsyncBean.class);
Caused by: java.lang.ClassCastException: $Proxy14 cannot be cast to AsyncBean
Can’t figure out how to use @Async with @EnableAsync….it seems to produce proxies and I can’t get a handle to the singleton.
Another example:
@Bean
public Bean bean(){
Bean bean=new Bean();
bean.registerHandler(asyncBean());
}
@Bean
public AsyncBean asyncBean(){
return new AsyncBean();
}
This also throws the same class cast exception… Caused by:
java.lang.ClassCastException: $Proxy14 cannot be cast to AsyncBean
Spring requires AsyncBean to be an interface not a class. In general the proxied class must be an interface.