spring mvc 依赖注入问题

Gabrain 发布于 2016/04/12 10:26
阅读 805
收藏 0

启动tomcat的时候就开始报异常,spring配置文件都已经检查过了 没有问题,请求各位大神解答

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'realNameAuthBusiness': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.zxhy.xjl.rna.service.RealNameAuthService com.zxhy.xjl.rna.business.impl.RealNameAuthBusinessImpl.realNameAuthService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'RealNameAuthService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.zxhy.xjl.rna.mapper.RealNameAuthMapper com.zxhy.xjl.rna.service.impl.RealNameAuthServiceImpl.mapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.zxhy.xjl.rna.mapper.RealNameAuthMapper] 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)}
 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
 at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444)
 at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326)
 at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
 at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4811)
 at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5251)
 at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
 at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
 at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
 at java.util.concurrent.FutureTask.run(FutureTask.java:266)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
 at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.zxhy.xjl.rna.service.RealNameAuthService com.zxhy.xjl.rna.business.impl.RealNameAuthBusinessImpl.realNameAuthService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'RealNameAuthService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.zxhy.xjl.rna.mapper.RealNameAuthMapper com.zxhy.xjl.rna.service.impl.RealNameAuthServiceImpl.mapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.zxhy.xjl.rna.mapper.RealNameAuthMapper] 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)}
 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
 at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
 ... 22 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'RealNameAuthService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.zxhy.xjl.rna.mapper.RealNameAuthMapper com.zxhy.xjl.rna.service.impl.RealNameAuthServiceImpl.mapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.zxhy.xjl.rna.mapper.RealNameAuthMapper] 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)}
 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
 
 
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.zxhy.xjl.rna.mapper.RealNameAuthMapper] 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)}
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1373)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1119)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
 ... 37 more

加载中
0
灰烬

错误不是写的很清楚吗?你是不是名字命名错了或者系统中有多个相同的命名

[com.zxhy.xjl.rna.mapper.RealNameAuthMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: 

灰烬
回复 @Gabrain : 你看看这个类的注入名字是不是不相同
Gabrain
Gabrain
名字没有重复
Gabrain
Gabrain
.RealNameAuthMapper你是说 这个命名重复了?
0
星无宇
星无宇
com.zxhy.xjl.rna.mapper  你的这个mapper的包名 有没有去扫描啊?
0
华兹格
华兹格

NoSuchBeanDefinitionException: No qualifying bean of type [com.zxhy.xjl.rna.mapper.RealNameAuthMapper] found for dependency: 


Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.zxhy.xjl.rna.mapper.RealNameAuthMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: 

用@Qualifier 指定具体的实现类。

0
培公啊
培公啊
有没有对应的Mapper.java对应的xml呢,xml的namespace是不是Mapper.java的全限定名呢
培公啊
培公啊
回复 @Gabrain : 感觉不是web.xml里边的问题,你之前报的错表明了已经找到ApplicationContext.xml了,你改了之后不出问题可能是没有找到xml去实例化bean,你可以看下console里有没有创建bean的相关log,你这个问题感觉就是Mapper的问题,2楼说的MapperScanner你配了吗,最好吧ApplicationContext.xml贴一下
Gabrain
Gabrain
我刚刚试了一下 把web.XML里面引用xml的格式改成classpath*:/ApplicationContext-/*.xml 这样启动就不报错了,但是servlet映射好像就访问不了了
Gabrain
Gabrain
这个是有的 namespace="com.zxhy.xjl.rna.mapper.RealNameAuthMapper"
返回顶部
顶部