0

I want to connect two different MySQL databases with spring boot application. I want application to be able to communicate with both databases at the same time.

2
  • Just have two datasources and communicate with the correct database when you need to interact with it? There are numerous articles about this subject. Please do some research first. That is a part of your job. Commented May 30, 2018 at 6:34
  • Possible duplicate of: stackoverflow.com/questions/30337582/… Commented May 30, 2018 at 6:35

1 Answer 1

1

You have to decleare different keys for different datasource.

@Bean
@Primary
@ConfigurationProperties("mysql.connection1")
public DataSourceProperties connectionProp1() {
    return new DataSourceProperties();
}

@Bean
@Primary
@ConfigurationProperties("mysql.connection1")
public DataSource connection1() {
    return connectionProp1().initializeDataSourceBuilder().build();
}
@Bean
@Primary
@ConfigurationProperties("mysql.connection2")
public DataSourceProperties connectionProp2() {
    return new DataSourceProperties();
}

@Bean
@Primary
@ConfigurationProperties("mysql.connection2")
public DataSource connection2() {
    return connectionProp2().initializeDataSourceBuilder().build();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.