74.2 Configure Two DataSources

Creating more than one data source works the same as creating the first one. You might want to mark one of them as @Primary if you are using the default auto-configuration for JDBC or JPA (then that one will be picked up by any @Autowired injections).

_@Bean_
_@Primary_
_@ConfigurationProperties(prefix="datasource.primary")_
public DataSource primaryDataSource() {
    return DataSourceBuilder.create().build();
}

_@Bean_
_@ConfigurationProperties(prefix="datasource.secondary")_
public DataSource secondaryDataSource() {
    return DataSourceBuilder.create().build();
}

results matching ""

    No results matching ""