抛出异常
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'adminService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private pers.zww.grad.dao.IAdminDao pers.zww.grad.service.impl.AdminServiceImpl.adminDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [pers.zww.grad.dao.IAdminDao] 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), @org.springframework.beans.factory.annotation.Qualifier(value=adminDao)}
此为自动生成的Mapper,我加了注解@Repository
package pers.zww.grad.dao;
import org.springframework.stereotype.Repository;
import pers.zww.grad.vo.Admin;
@Repository("adminDao")
public interface IAdminDao {
int deleteByPrimaryKey(String id);
int insert(Admin record);
int insertSelective(Admin record);
Admin selectByPrimaryKey(String id);
int updateByPrimaryKeySelective(Admin record);
int updateByPrimaryKey(Admin record);
Integer getCountByName(String name);
Integer getCountByNameAndPass(String name,String password);
}
这是Service里面注入
package pers.zww.grad.service.impl;
、、、
@Service("adminService")
public class AdminServiceImpl implements IAdminService {
@Autowired
@Qualifier("adminDao")
private IAdminDao adminDao;
@Override
public int deleteByPrimaryKey(String id) {
// TODO Auto-generated method stub
return 0;
}
配置文件都已扫描过了,而且相关mybatis的如下:
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- 自动扫描mapping.xml文件 -->
<property name="mapperLocations" value="classpath:pers/zww/grad/mapping/*.xml"></property>
</bean>
<!-- DAO接口所在包名,Spring会自动查找其下的类 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="pers.zww.grad.dao" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean>
IAdminDao 没有被init,看下是否有这个bean,如果没有加上,如果有则看下xml有没有关联到spring的xml上
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。