SpringBoot injecting Service failed

Description:

The bean 'userService' could not be injected as a 'com.phy.hemanresoruce.service.UserService' because it is a JDK dynamic proxy that implements:

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.

 

1.

According to the above description, the Bean failed userServiceImpl injection (reason for the failure is to implement an interface, and springboot affairs default is to use jdk dynamic proxy, which is based on the interface)). Implanted layer in the action Bean is implementation class, so will be given.

Solution: Bean injected this way changed its interface


2.

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.

Look again at the idea to the proposal: can be considered under the action of the injected Bean interface mode or forced into the transaction using CGLib proxy mode (class-based, that is set proxyTargetClass = True @EnableTransactionManagement (proxyTargetClass = True on the boot transaction management)) such agents in cGLib manner, as previously written, it should be necessary to introduce appropriate cglib jar package library. In springboot it is already integrated.

Guess you like

Origin www.cnblogs.com/phyqxx/p/11572239.html