autowire异常的三个情况

Java代码   收藏代码
  1. 2010-3-11 16:06:00 net.sf.ehcache.config.ConfigurationFactory parseConfiguration  
  2. 警告: No configuration found. Configuring ehcache from ehcache-failsafe.xml  found in the classpath: jar:file:/E:/kenny/%e9%a1%b9%e7%9b%ae/shops/webapp/WEB-INF/lib/ehcache-1.6.1.jar!/ehcache-failsafe.xml  
  3. 2010-03-11 16:06:02,734 [main] ERROR [org.springframework.test.context.TestContextManager] - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@1292d12] to prepare test instance [com.zzh.entity.product.BrandServiceImplTest@4e32c8]  
  4. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.zzh.entity.product.BrandServiceImplTest': Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.zzh.service.product.impl.BrandServiceImpl com.zzh.entity.product.BrandServiceImplTest.brandServiceImpl; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'brandServiceImpl': Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.zzh.dao.product.BrandDao com.zzh.service.product.impl.BrandServiceImpl.brandDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.zzh.dao.product.BrandDao] is defined: Unsatisfied dependency of type [class com.zzh.dao.product.BrandDao]: expected at least 1 matching bean  
  5.     at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessAfterInstantiation(AutowiredAnnotationBeanPostProcessor.java:243)  
  6.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:959)  
  7.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:329)  
  8.     at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:110)  
  9.     at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)  
  10.     at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:255)  
  11.     at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:111)  
  12.     at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:148)  
  13.     at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)  
  14.     at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)  
  15.     at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)  
  16.     at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)  
  17.     at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)  
  18.     at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:97)  
  19.     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)  
  20.     at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)  
  21.     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)  
  22.     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)  
  23.     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)  
  24.     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)  
  25. Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.zzh.service.product.impl.BrandServiceImpl com.zzh.entity.product.BrandServiceImplTest.brandServiceImpl; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'brandServiceImpl': Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.zzh.dao.product.BrandDao com.zzh.service.product.impl.BrandServiceImpl.brandDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.zzh.dao.product.BrandDao] is defined: Unsatisfied dependency of type [class com.zzh.dao.product.BrandDao]: expected at least 1 matching bean  
  26.     at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:435)  
  27.     at org.springframework.beans.factory.annotation.InjectionMetadata.injectFields(InjectionMetadata.java:105)  
  28.     at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessAfterInstantiation(AutowiredAnnotationBeanPostProcessor.java:240)  
  29.     ... 19 more  
  30. Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'brandServiceImpl': Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.zzh.dao.product.BrandDao com.zzh.service.product.impl.BrandServiceImpl.brandDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.zzh.dao.product.BrandDao] is defined: Unsatisfied dependency of type [class com.zzh.dao.product.BrandDao]: expected at least 1 matching bean  
  31.     at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessAfterInstantiation(AutowiredAnnotationBeanPostProcessor.java:243)  
  32.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:959)  
  33.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)  
  34.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)  
  35.     at java.security.AccessController.doPrivileged(Native Method)  
  36.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)  
  37.     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)  
  38.     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)  
  39.     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)  
  40.     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)  
  41.     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)  
  42.     at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:671)  
  43.     at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:610)  
  44.     at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:412)  
  45.     ... 21 more  
  46. Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.zzh.dao.product.BrandDao com.zzh.service.product.impl.BrandServiceImpl.brandDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.zzh.dao.product.BrandDao] is defined: Unsatisfied dependency of type [class com.zzh.dao.product.BrandDao]: expected at least 1 matching bean  
  47.     at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:435)  
  48.     at org.springframework.beans.factory.annotation.InjectionMetadata.injectFields(InjectionMetadata.java:105)  
  49.     at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessAfterInstantiation(AutowiredAnnotationBeanPostProcessor.java:240)  
  50.     ... 34 more  
  51. Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.zzh.dao.product.BrandDao] is defined: Unsatisfied dependency of type [class com.zzh.dao.product.BrandDao]: expected at least 1 matching bean  
  52.     at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:613)  
  53.     at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:412)  
  54.     ... 36 more  

 autowire异常主要由三个情况发生的

像上面的情况是BrandDao没有注入,


1。你的BrandServiceImpl必须以@Service或@Component注解才行。

 

2。自动写入的时候把接口写成实现类了 
@Autowired 
private BrandServiceImpl      brandServiceImpl; 
应该是 
@Autowired 
private BrandService    brandService ;

 

3.在BrandDao 类上加上@Repository注解

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值