Skip to content

Spring boot cannot start with two or more DataSources #5104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
quaso opened this issue Feb 8, 2016 · 2 comments
Closed

Spring boot cannot start with two or more DataSources #5104

quaso opened this issue Feb 8, 2016 · 2 comments

Comments

@quaso
Copy link

quaso commented Feb 8, 2016

DataSourceInitializer init method fails, because it works only if there is just one DataSource bean in the context>

if (this.applicationContext.getBeanNamesForType(DataSource.class, false, false).length > 0) { this.dataSource = this.applicationContext.getBean(DataSource.class); }

Either change condition in if clause to "== 0" or handle org.springframework.beans.factory.NoUniqueBeanDefinitionException prope

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 8, 2016
@vavrekm
Copy link

vavrekm commented Feb 8, 2016

Found workaround solution - exlude autoconfiguration of Datasources:

@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class, HibernateJpaAutoConfiguration.class })

Also discussed here:
http://stackoverflow.com/questions/27843788/resource-annotation-no-qualifying-bean-of-type-javax-sql-datasource-is-define

@wilkinsona
Copy link
Member

I'm pleased to hear that you've found a workaround. An alternative that you might like to consider is to mark one of your DataSource beans as @Primary.

Also, you may be interested to know that the general situation will improve in 1.4.0.M2 when #2784 is implemented. It will mean that the initialiser backs off when there are multiple DataSource beans to choose from rather than failing as it currently does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants