Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The bean could not be injected as a 'Type' because it is a JDK dynamic proxy that implements: reactor.fn.Consumer

My Spring 4 application, which uses Reactor 2, fails to start with:

*************************** APPLICATION FAILED TO START ***************************  Description:  The bean 'orderHandlerConsumer' could not be injected as a 'fm.data.repository.OrderHandlerConsumer' because it is a JDK dynamic proxy that implements:     reactor.fn.Consumer   Action:  Consider injecting the bean as one of its interfaces or forcing the use of CGLib-based proxies by setting proxyTargetClass=true on @EnableAsync and/or @EnableCaching. 

The OrderHandlerConsumer is really simple:

@Service @Order(Ordered.HIGHEST_PRECEDENCE) public class OrderHandlerConsumer implements Consumer<Event<OrderEnvelope>> {     @Override     public void accept(Event<OrderEnvelope> event) {         event.getData().getLatch().countDown();     } } 

Any ideas what might be going awry?

like image 214
Jan Nielsen Avatar asked Jul 16 '17 03:07

Jan Nielsen


People also ask

What is JDK dynamic proxy?

JDK Dynamic Proxies allow one to create implementations of Java interfaces at runtime by the means of Reflection. A proxy may be seen as a subject that will forward method calls to target instances and eventually return any result produced by the target instance to the caller.

How are JDK dynamic proxies used in spring?

Spring AOP uses either JDK dynamic proxies or CGLIB to create the proxy for a given target object. (JDK dynamic proxies are preferred whenever you have a choice). If the target object to be proxied implements at least one interface then a JDK dynamic proxy will be used.

How are JDK dynamic proxy and Cglib proxy?

JDK dynamic proxy is available with the JDK. It can be only proxy by interface so target class needs to implement interface. In your is implementing one or more interface then spring will automatically use JDK dynamic proxies. On the other hand, CGLIB is a third party library which spring used for creating proxy.


1 Answers

In your application class file where you define it as Spring application, add underneath it.

@SpringBootApplication @EnableCaching(proxyTargetClass = true) 
like image 68
Rohan Avatar answered Sep 22 '22 03:09

Rohan