Error creating bean with name 'xxxx': Injection of autowired dependencies failed;

4030 ワード

ssm統合時にこのエラーが発生しました.具体的には次のエラーを報告します.
Error creating bean with name ‘UserInfoService’: Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.car.dao.IUserInfoDAO com.car.service.UserInfoService.iUserInfoDAO; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.car.dao.IUserInfoDAO] 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)}
この文を見てください.
No qualifying bean of type [com.car.dao.IUserInfoDAO] found for dependency

私のdaoレイヤインタフェースが見つからないのでspring-configをチェックします.xmlの下の配置、ただsqlSessionFactoryを配置してMapperScannerConfigurerを書くことを忘れたことを発見して、MapperScannerConfigurerの作用は私達のdao層のマッパーのインタフェースをスキャンします
    
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        
        <property name="mapperLocations" value="classpath:mapper/*.xml"/>
        
        <property name="typeAliasesPackage" value="com.car.entity"/>
        
        <property name="configLocation" value="classpath:mybatis-config.xml"/>
    bean>

    
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.car.dao">property>
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory">property>
    bean>

このエラーには多くの原因があります.多くの原因は、構成が間違っているか、書き忘れているため、チェックしてください.