gpt4 book ai didi

java - 交易注解错误

转载 作者:搜寻专家 更新时间:2023-10-30 19:51:02 26 4
gpt4 key购买 nike

当我在我的服务类中放置“@Transactional(readOnly=false)”注释时,出现以下错误

描述:

The bean 'studentService' could not be injected as a 'com.student.service.StudentServiceImpl' because it is a JDK dynamic proxy that implements: com.student.service.StudentService

示例代码:

@Service("studentService")
@Transactional(readOnly=false)
public class StudentServiceImpl implements StudentService {

}

public interface StudentService {

}

行动:

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.

Process finished with exit code 1

是什么原因造成的?

最佳答案

正如评论中已经提到的那样,当您尝试注入(inject)/ Autowiring 实现类而不是接口(interface)时会发生错误。

The bean 'studentService' could not be injected as a 'com.student.service.StudentServiceImpl' because it is a JDK dynamic proxy that implements: com.student.service.StudentService

在 SO 发布的设置上,

public class StudentServiceImpl implements StudentService {
}

public interface StudentService {
}

如果你按照下面的方式自动连接接口(interface),你将不会收到错误:

@Autowired //or @Inject
StudentService studentService;

关于java - 交易注解错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39483059/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com