今天測試spring、springmvc、mybatis,分層為dao、service、serviceimpl、controller,在運行的時候提示
1 org.apache.catalina.core.ApplicationContext.log StandardWrapper.Throwable 2 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'XXXController':
Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No matching bean of type [com.XX.service.IXXService] 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=class java.lang.Object, mappedName=)} 3 at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:306) 4 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106) 5 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) 6 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
我所有的注解都已經寫好的:
dao @Repository
serviceimpl @Service
controller @Controller
並且spring配置文件也寫好自動掃描,位置也正確。但錯誤一直都在
折騰了一晚上才發現,spring監聽配置被注釋掉了
在web.xml里面還原spring的監聽配置
1 <listener> 2 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 3 </listener> 4 <listener> 5 <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class> 6 </listener>
然后問題解決了