spring单元测试时No qualifying bean of type [javax.sql.DataSource] is defined: expected single matching bean but found 2

No qualifying bean of type [javax.sql.DataSource] is defined: 
expected single matching bean but found 2

从报错的信息来看, 没有一个具备资格的DataSource类型的bean。 期望一个,结果找到了多个。  从信息的内容来看,可以看出来应该是定义了多个datasource 类型的bean。 可能在使用默认datasource类型的bean时候,犯迷糊了。

1) 可能使用多个数据源? https://github.com/spring-projects/spring-data-examples/tree/master/multi-store  可以参考多个数据源的配置。

2) 我这里发现,因为被依赖的工程里有class的configuration和xml中的定义有重复。 所以在spring.xml 中, exclude  @configuration的class。 这样不会和xml中的定义冲突。

<context:component-scan base-package="com.hissummer.app">
<context:exclude-filter type="annotation"
expression="org.springframework.context.annotation.Configuration" />
</context:component-scan>

 

此篇文章已被阅读2697 次

Tags:

Add a Comment

邮箱地址不会被公开。 必填项已用*标注