如下报错详情:
Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loginservice': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.suxin.dao.IUserDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, lookup=, name=, description=, authenticationType=CONTAINER, type=interface com.suxin.dao.IUserDao, mappedName=)}
service:
@Service("loginservice")
public class LoginServiceImpl implements ILoginService{
@Resource(type = IUserDao.class)
private IUserDao userDao;
@Override
public void insertUser(UserInfoModel userinfo){
userDao.insertUser(userinfo);
}
}
Dao:
public interface IUserDao {
String insertUser(UserInfoModel userInfo);
}
spring配置:
<!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- 自动扫描mapping.xml文件 -->
<property name="mapperLocations" value="classpath:mapping/*.xml"></property>
</bean>
<!--DAO接口所在包名,Spring会自动查找其下的类-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
<property name="basePackage" value="com.suxin.dao" />
<property name="annotationClass" value="org.springframework.stereotype.Repository" />
</bean>
<!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
mapper的扫描用下面这个试试
<mybatis:scan base-package="你的mapper包路径" />
<!-- 自动扫描 -->
<context:component-scan base-package="com.suxin.dao"/>
<context:component-scan base-package="com.suxin.service"/>
有加着。包的路径也都没有问题。
@斗破山河: 你试一试,这是不一样的
@Resource(type = IUserDao.class)
private IUserDao userDao;
换成
@Resource
private IUserDao userDao;
试试