Transactional Annotation Error

When I add the annotation " @Transactional(readOnly=false) " in my "Service" class, I get the following error:

Description:

bean 'studentService' cannot be entered as ' com.student.service.StudentServiceImpl ' because it is a JDK proxy dynamics that implements: com.student.service.StudentService

Code example:

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

Act:

Consider inserting a bean as one of its interfaces or force the use of CGLib-based proxies by setting proxyTargetClass=true to @EnableAsync and / or @EnableCaching .

Process terminated with exit code 1

What causes this?

+7
java spring-boot
source share
2 answers

As mentioned in the comment on SO, an error occurs when you try to introduce the / autowire implementation class instead of an interface.

bean 'studentService' cannot be entered as 'com.student.service.StudentServiceImpl' because it is a JDK proxy dynamics that implements: com.student.service.StudentService

In the settings sent by SO,

 public class StudentServiceImpl implements StudentService { } public interface StudentService { } 

If you disable the interface as shown below, you will not receive an error:

 @Autowired //or @Inject StudentService studentService; 
+6
source share

in spring boot projects, try adding:

 spring.aop.proxy-target-class=true 

to your application.properties

OR

 @EnableAspectJAutoProxy(proxyTargetClass = true) 

to the spring boot point.

+6
source share

All Articles