问题

  1. @Resource
  2. private TemplatePlatformMallExtMapper templatePlatformMallMapper;

templatePlatformMallMapper同时存在的时候,使用@Resource注入会启动报错。

  1. 2021-12-22 15:15:03.774 ERROR [bmp-prm-service,,,] 25444 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
  2. ***************************
  3. APPLICATION FAILED TO START
  4. ***************************
  5. Description:
  6. The bean 'templatePlatformMallMapper' could not be injected as a 'com.vevor.prm.mapper.template.platform.TemplatePlatformMallExtMapper' because it is a JDK dynamic proxy that implements:
  7. com.vevor.prm.mapper.template.platform.TemplatePlatformMallMapper
  8. Action:
  9. Consider injecting the bean as one of its interfaces or forcing the use of CGLib-based proxies by setting proxyTargetClass=true on @EnableAsync and/or @EnableCaching.

原因

  1. 当用`@Resource`注入类的时候,他会优先按照名称去注入,所以当命名为`templatePlatformMallMapper`会首先查找`TemplatePlatformMallMapper`这个类而不是`TemplatePlatformMallExtMapper`这个类,所以启动报错

解决办法

  • 换为@Autowired注入
  • 注入时候的templatePlatformMallMapper变量名称修改为其他未存在的类名驼峰命名,如templatePlatformMallExtMapper