交易注释错误
当我在我的Service类中添加“ @Transactional(readOnly=false)
”注释时,我收到以下错误
描述:
bean“studentService”无法作为“
com.student.service.StudentServiceImpl
”注入,因为它是一个实现的JDK动态代理:com.student.service.StudentService
示例代码:
@Service("studentService") @Transactional(readOnly=false) public class StudentServiceImpl implements StudentService { } public interface StudentService { }
行动:
考虑通过在
@EnableAsync
和/或@EnableCaching
上设置proxyTargetClass=true
来将bean注入其接口之一或强制使用基于CGLib的代理。进程以退出代码1结束
是什么造成的?
在spring boot项目中,尝试添加:
spring.aop.proxy-target-class=true
到您的application.properties
要么
@EnableAspectJAutoProxy(proxyTargetClass = true)
到你的春季启动入口点。
正如SO已在评论中提到的那样,当您尝试注入/自动assembly实现类而不是接口时,会发生错误。
bean“studentService”无法作为“com.student.service.StudentServiceImpl”注入,因为它是一个实现的JDK动态代理:com.student.service.StudentService
在SO发布的设置上,
public class StudentServiceImpl implements StudentService { } public interface StudentService { }
如果您按如下所示自动连接界面,则不会出现错误:
@Autowired //or @Inject StudentService studentService;