1. 程式人生 > 其它 >解決:Could not autowire. No beans of 'XXXXXXXXXX' type found.

解決:Could not autowire. No beans of 'XXXXXXXXXX' type found.

針對於不能夠正常編譯執行的解決方案:正確的匯入包,如果是檢查錯誤提示中的類的包是否匯入正確,這種錯誤最常見在mybatis中的mapper下,比如對於mybatis的的註解版或配置檔案版的解決辦法:

    ①.配置檔案版:在全域性配置檔案中,配置要自動掃描進容器的包

<!-- mapper scanner configurer -->
<bean id="mapperScannerConfig" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage
" value="com.wp.spring.mybatis.dao" /> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" /> </bean> ②.註解版:在執行的主類上加上註解:@MapperScan(value = "要自動掃描的包")-->(springboot整合mybatis的時候)。或則在mybatis專案中的mapper類上面加上註解@Mapper標識這是一個mapper,容器啟動的時候就會自動加入到容器中了。示例如下:

 

 

    2
.mybatis的mapper類: