syv*_*syv 14 java dependency-injection spring-boot
当我@Transactional(readOnly=false)在我的Service类中添加" "注释时,我收到以下错误
描述:
bean"studentService"无法作为'
com.student.service.StudentServiceImpl' 注入,因为它是一个实现的JDK动态代理:com.student.service.StudentService
示例代码:
@Service("studentService")
@Transactional(readOnly=false)
public class StudentServiceImpl implements StudentService {
}
public interface StudentService {
}
Run Code Online (Sandbox Code Playgroud)
行动:
考虑将bean注入其接口之一或通过设置
proxyTargetClass=trueon@EnableAsync和/或强制使用基于CGLib的代理@EnableCaching.进程以退出代码1结束
是什么造成的?
gti*_*333 17
正如在评论中已经提到的那样,当您尝试注入/自动装配实现类而不是接口时,会发生错误.
bean"studentService"无法作为"com.student.service.StudentServiceImpl"注入,因为它是一个实现的JDK动态代理:com.student.service.StudentService
在SO发布的设置上,
public class StudentServiceImpl implements StudentService {
}
public interface StudentService {
}
Run Code Online (Sandbox Code Playgroud)
如果您按如下所示自动连接界面,则不会出现错误:
@Autowired //or @Inject
StudentService studentService;
Run Code Online (Sandbox Code Playgroud)
小智 16
在spring boot项目中,尝试添加:
spring.aop.proxy-target-class=true
Run Code Online (Sandbox Code Playgroud)
到您的application.properties
要么
@EnableAspectJAutoProxy(proxyTargetClass = true)
Run Code Online (Sandbox Code Playgroud)
到你的春季启动入口点.
| 归档时间: |
|
| 查看次数: |
16480 次 |
| 最近记录: |