springmvc中@Transactional和@Service一起使用时,无法装配

img

img


以上这样配置运行就会提示如下:

根本原因。

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mainController': Unsatisfied dependency expressed through field 'goodsOptionsImpl'; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'goodsOptionsImpl' is expected to be of type 'Service.Imply.GoodsOptionsImpl' but was actually of type 'jdk.proxy3.$Proxy34'

然后删除@Transactional就可以运行,这是为什么

改为接口注入 实现类注入你就别用@Qualifier了

@Autowired
GoodsOptions goodsOptions;

跟事务注解没啥关系