Define bean aliases using spring java config

We have several DB connections in our application and, therefore, several configurations for JPA. Configurations differ only in types of schema name, database node name, etc. The rest, for example, setting sleep mode, etc. (Usually) are the same. The result is multiple HibernateJpaVendorAdapter, data source, etc. beans. They all need different names so that they do not come across. We are currently installing this manually, for example:

@Configuration
@Bean
public class FooDbConfig {
     public DataSource fooDataSource() {
         return ...;
     }
     // ... more beans like HibernateJpaVendorAdapter etc.
} 

@Configuration
@Bean
public class BarDbConfig {
     public DataSource barDataSource() {
         return ...;
     }
     // ... more beans like HibernateJpaVendorAdapter etc.
} 

This, of course, is very fragile to maintain.

- java config "", ​​ beans, bean. beans ( ..) , (, "fooDataSource" "barDataSource" ).

?

bean java config?

+4

All Articles