为了账号安全,请及时绑定邮箱和手机立即绑定

多使用一个注解报错,当我注释掉私有变量上的autowired的注解,只是用service注解时,就不报错了,求解释

Loading XML bean definitions from class path resource [resources/spring-beaninjectannotation.xml]

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'injectionServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private injectiondao.InjectionDao injectannotation.InjectionServiceImpl.injectionDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [injectiondao.InjectionDao] 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:292)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)

at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)

at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)

at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)

at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)

at base.UnitTestBase.before(UnitTestBase.java:28)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.la


正在回答

2 回答

我猜测会不会是你的注解的成员变量的变量名有问题。

0 回复 有任何疑惑可以回复我~

很明显injectionServiceImpl注入的时候没有找到对应类,报了 NoSuchBeanDefinitionException,猜想是injectionServiceImpl上的autowired去掉后(spring就不去找这个类而已),这个变量没有被注入,只是一个null;楼主只是没有使用这个对象所以没有发现。希望可以给你一些参考

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Spring入门篇
  • 参与学习       268787    人
  • 解答问题       963    个

为您带来IOC和AOP的基本概念及用法,为后续高级课程学习打下基础

进入课程

多使用一个注解报错,当我注释掉私有变量上的autowired的注解,只是用service注解时,就不报错了,求解释

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信