2016-09-14 81 views
7

当我把 “@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 { 

} 

操作:

考虑将bean注入其中一个接口或强制使用CGLib-通过在@EnableAsync和/或@EnableCaching上设置proxyTargetClass=true来实现基于代理的代理。

进程退出代码为1

是什么原因造成完了?

+0

如果您尝试使用JRE构建项目,那么您可以将其更改为JDK吗?你的类路径中是否有所有与方面相关的jar? – Nimesh

+5

这是我的错误,我已经自动布线了Interface的实现类。 – syv

+0

你可以用这个答案回答你自己的问题,因为我遇到了同样的事情,这帮助我解决了这个问题。谢谢! – emilyk

回答

6

由于已经在评论中提到过,当您尝试注入/ autowire实现类而不是接口时会发生错误。

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

上公布通过这样的设置,

public class StudentServiceImpl implements StudentService { 
} 

public interface StudentService { 
} 

如果自动装配界面如下,你不会得到一个错误:在春季启动项目

@Autowired //or @Inject 
StudentService studentService; 
+0

如果界面有很多实现,弹簧如何知道我要注入哪一个? – Nurlan

+1

@Nurlan检查限定符注释 –

5

,尝试加:

spring.aop.proxy-target-class=true 

到你的application.pr operties

OR

@EnableAspectJAutoProxy(proxyTargetClass = true) 

你的春天引导入口点。