关于service中添加Transaction注解后,service无法注入bean

如果不添加@Transactional就可以执行,添加后就出问题

service类

图片说明

测试类
图片说明

错误提示:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService' defined in class path resource [bean.xml]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Unexpected AOP exception; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'org.springframework.transaction.interceptor.TransactionInterceptor#0' must be of type [org.aopalliance.aop.Advic

你的@Transactional应该放在service中的具体方法上,而不是放在类上。

那你的UserService上有没有@Service注解呢?同时加上这两个注解才可以啊。