问题记录
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘com.mao.dao.CategoryDao’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
@Repository注解已添加
spring-mybatis配置 文件
在service中注入CategoryDao的时候出现上面的错误,我找了好久原因。一开始也不知道什么原因。后来发现都是自己惹的祸,本来mybatis所有的配置信息都写在applicationContext.xml中的,突然想分得清晰一些就新建了一个spring-mybatis.xml整合mybatis相关配置。整合以后忘记把spring-mybatis.xml引入到applicationContext.xml中了。而我的web.xml是配置applicationContext.xml的。所以导致spring-mybatis.xml根本没有被用到。太粗心。
web.xml
applicationContext.xml配置文件