Skip to content

org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker circular reference Spring Boot 2.1.3 #19665

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
AleksandarTokarev opened this issue Jan 13, 2020 · 7 comments

Comments

@AleksandarTokarev
Copy link

AleksandarTokarev commented Jan 13, 2020

I just upgraded my app from Spring Boot 1.5.9 to 2.1.3. We have 2 databases, one non sharded and the other one is sharded. When trying to start the application, i get the following error:

┌─────┐
|  shardedDataSource defined in class path resource [com/config/ShardedDataSourceConfig.class]
↑     ↓
|  globalNamedParameterJdbcTemplate defined in class path resource [com/config/GlobalDataSourceConfig.class]
↑     ↓
|  globalJdbcTemplate defined in class path resource [com/config/GlobalDataSourceConfig.class]
↑     ↓
|  global defined in class path resource [com/config/GlobalDataSourceConfig.class]
↑     ↓
|  org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker
└─────┘

In GlobalDataSourceConfig i have the following Beans

@Bean(name = "global")
    public DataSource globalDataSource() {
        return new HikariDataSource(this);
    }

    @Bean(name = "globalJdbcTemplate")
    public JdbcTemplate globalJdbcTemplate() {
        return new JdbcTemplate(globalDataSource());
    }

    @Bean(name="globalNamedParameterJdbcTemplate")
    public NamedParameterJdbcTemplate globalNamedParameterJdbcTemplate() {
        return new NamedParameterJdbcTemplate(globalJdbcTemplate());
    }

And for the shardedDataSource in ShardedDataSourceConfig class i have

  @Primary @Bean @Profile("!test")
    public DataSource shardedDataSource(@Qualifier("globalNamedParameterJdbcTemplate") NamedParameterJdbcTemplate jdbcTemplate) {

Anyone can give me an idea why this happens?
Before the upgrade this was not happening.
I found a similar issue but the solution is not working for SpringBoot 2

#9394

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 13, 2020
@wilkinsona
Copy link
Member

It's very hard to say with this might be happening based only on 4 bean definitions. Please try upgrading to the latest Spring Boot 2.1.x or 2.2.x release. If the problem remains, please provide a small sample (a complete, minimal project in an attached zip or separate GitHub repo) that reproduces the problem and we can take a look.

@wilkinsona wilkinsona added status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 13, 2020
@AleksandarTokarev
Copy link
Author

AleksandarTokarev commented Jan 13, 2020

The repository provided by zach in #9394
gives a good explanation of the problem in the Readme
https://github.com/zachmarshall/spring-datasource-init-bug

Atm we are kinda limited to using Spring Boot 2.1.3 because of some other dependencies that we have.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jan 13, 2020
@wilkinsona
Copy link
Member

The problem in #9394 has a workaround but you said above that "the solution is not working" so, presumably, your problem isn't the same. Without knowing more about wha is different in your case we aren't going to be able to help you. If you would like us to spend some more time looking at this, please take the time to provide the information that we need to be able to do so. In this case that's a small sample project that reproduces your specific problem.

@wilkinsona wilkinsona added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Jan 13, 2020
@AleksandarTokarev
Copy link
Author

Well if u look at the issue in #9394 , @rvit34 has stated that the solution is not working for him as well in Spring Boot 2

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jan 13, 2020
@wilkinsona
Copy link
Member

That's not entirely surprising as @rvit34 has a different (and more complicated) setup.

As I said above, if you would like us to spend some more time looking at this, please take the time to provide the information that we need to be able to do so. If you aren't in a position to do so then I'm afraid you'll have to look elsewhere for some help.

@wilkinsona wilkinsona added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Jan 13, 2020
@AleksandarTokarev
Copy link
Author

Please have a look at this Branch, which fails on Spring Boot 2
https://github.com/zachmarshall/spring-datasource-init-bug/tree/spring-boot-2
He has this problem explained in this branch.
The test in the class TestPassesWithInitializerDisabled is an example.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jan 13, 2020
@wilkinsona
Copy link
Member

I see you've also posted this on Stack Overflow. In the interests of avoiding duplicated effort, I'm going to close this issue. If you update your question on Stack Overflow with a minimal, complete, and verifiable example I or someone else in the Spring Boot community may be able to help you. Please note that the example should be for your specific problem rather than someone else's. DataSource initialization is more complicated then we would like and a fix or workaround for someone else's problem may not help you with yours.

@wilkinsona wilkinsona removed status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged labels Jan 14, 2020
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

3 participants