I have an application that runs Spring MVC.
I need it to access 2 different User of same DB in my app.
How do I configure this using application.properties file?
application.properties file
jdbc.driverClassName=oracle.jdbc.driver.OracleDriver
jdbc.url=jdbc:oracle:thin:@myoracle.db.server:1521:my_sid
jdbc.username=USERA
jdbc.password=passwrord1
jdbc.driverClassName=oracle.jdbc.driver.OracleDriver
jdbc.url=jdbc:oracle:thin:@myoracle.db.server:1521:my_sid
jdbc.username=USERB
jdbc.password=passwrord2
Regards.
CodePudding user response:
Creating more than one data source works 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();
}