@autowire 注入失敗
idea 啟動報錯
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'WXCouponSupplyServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.community.shop.mapper.WXCouponSupplyDOMapper com.community.shop.service.impl.WXCouponSupplyServiceImpl.wxCouponSupplyDOMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.community.shop.mapper.WXCouponSupplyDOMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
1.檢查服務層是否新增@Service 註解
@Service public class FundsInvestServiceImpl implements IFundsInvestService{ @Autowired private FundsInvestDOMapper fundsInvestDOMapper;
2.檢查啟動類是否添加註解@MapperScan掃描mapper檔案
@SpringBootApplication //開啟註解事務管理 @EnableTransactionManagement //掃描com.community.shop.mapper下的檔案 @MapperScan("com.community.shop.mapper") //定時任務 @EnableScheduling public class Application { public static void main(String args[]){ SpringApplication.run(Application.class); } }