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

Jan Nielsen picture Jan Nielsen · Jul 16, 2017 · Viewed 13.1k times · Source

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?

Answer

Rohan picture Rohan · Nov 12, 2019

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

@SpringBootApplication
@EnableCaching(proxyTargetClass = true)