TAG

RSS订阅

收藏本站

设为首页

当前位置:主页 > 服务端开发 > Java开发 > Spring开发学习 >

Spring整合mybatis 报错 Could not autowire method

发布时间:2015-11-13 00:15 类别:Spring开发学习

Spring整合mybatis 报错 Could not autowire method

 

Code:

Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests.setDataSource(javax.sql.DataSource); nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [javax.sql.DataSource] is defined: expected single matching bean but found 10: [dataSource, xDataSource, yDataSource,........]

   [junit]  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredElement.inject(AutowiredAnnotationBeanPostProcessor.java:421)

   [junit]  at org.springframework.beans.factory.annotation.InjectionMetadata.injectMethods(InjectionMetadata.java:69)

   [junit]  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:241)

   [junit]  ... 16 more

   [junit] Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [javax.sql.DataSource] is defined: expected single matching bean but found 10: [dataSource, xDataSource, yDataSource, ......]

   [junit]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveDependency(AbstractAutowireCapableBeanFactory.java:425)

   [junit]  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredElement.inject(AutowiredAnnotationBeanPostProcessor.java:397)

   [junit]  ... 18 more

 

and my test is :

Code:

@ContextConfiguration(locations={"file:dist/workplace/WEB-INF/spring/*.xml"})

public abstract class TransactionalBaseTest extends AbstractTransactionalJUnit4SpringContextTests {

   @Override

   @Resource

   public void setDataSource(DataSource dataSource) {

       super.setDataSource(dataSource);

   }

   

  public TransactionalBaseTest(){

  }

}

Code:

public class OrderTest extends TransactionalBaseTest {

 

   @Test

   public void testInsertOrder(){

       System.out.println("in test");

       Assert.assertTrue(true);

   }

}

 

解决方法:

 

Code:

@Resource(name="somename")

or better use @Autowired together with @Qualifier

 

Code:

@Autowired

@Qualifier("somename")

 

猜你会喜欢....

Copyright © 2015 www.wahenzan.com 哇!很赞 版权所有 浙ICP备14030256号-1 Power by DedeCms

浙公网安备 33010602005986号

声明:本站所有文章除标明原创外,均来自网络转载,版权归原作者所有,如果有侵犯到您的权益,请联系本站删除 网站管理员:758763728

360网站安全检测平台