service层
@Service
public class ManagerService implements IManagerService{
@Resource
private ManagerUser managerUser;
/**
* 方法实现说明:实现用户登录
* @author 翟波
* @param
* @return
* @exception
* @date 2019/1/7 11:34
*/
@Override
public Integer login(User user) {
return managerUser.login(user);
}
}
dao层Mapper
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.admin.mapper.ManagerUserMapper">
<!--查询用户登录信息是否正确-->
<select id="login" parameterType="user">
select * from admin_user where username=#{username} and password=#{password};
</select>
</mapper>
报错:
Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'managerService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.admin.mapper.ManagerUser] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER, lookup=)}
这是我的接口命名:
public interface ManagerUser {
/**
* 方法实现说明:后台用户登录
* @author 翟波
* @param
* @return
* @exception
* @date 2019/1/7 11:29
*/
Integer login(User user);
}
还有就是spring配置文件中对dao对象的批量扫描生成中路径没改。。
<!--配置dao对象 批量扫描获取-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!--注入sqlsession-->
<property name="sqlSessionFactoryBeanName" value="factoryBean"/>
<!--指明要扫描的包-->
<property name="basePackage" value="com.shop.mapper"/>
</bean>
粘贴的代码。。。忘了改了 <property name="basePackage" value="com.admin.mapper"/>这样就好了
可以看出接口名与mapper。xml文件中的namespace是对不上的,所以在service实例化注入对象时发现根本没有我所注入的这个 private ManagerUser managerUser;的xml配置文件。