首页 新闻 会员 周边 捐助

ssm 框架 dao层注入失败

0
[待解决问题]

如下报错详情:

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>

斗破山河的主页 斗破山河 | 菜鸟二级 | 园豆:202
提问于:2018-05-09 17:04
< >
分享
所有回答(3)
0

mapper的扫描用下面这个试试

 <mybatis:scan base-package="你的mapper包路径" />

让我发会呆 | 园豆:2929 (老鸟四级) | 2018-05-09 17:10

<!-- 自动扫描 -->
<context:component-scan base-package="com.suxin.dao"/>
<context:component-scan base-package="com.suxin.service"/>

有加着。包的路径也都没有问题。

支持(0) 反对(0) 斗破山河 | 园豆:202 (菜鸟二级) | 2018-05-09 17:15

@斗破山河: 你试一试,这是不一样的

支持(0) 反对(0) 让我发会呆 | 园豆:2929 (老鸟四级) | 2018-05-09 17:24
0
不会摇头的风扇 | 园豆:443 (菜鸟二级) | 2018-05-10 09:42
0

@Resource(type = IUserDao.class)

private IUserDao userDao;

换成

@Resource

private IUserDao userDao;

试试

、熙和 | 园豆:1508 (小虾三级) | 2018-05-12 13:28
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册