Sometimes you need to connect to multiple databases, data sources are inconsistent and need to be configured.
1, configuration XML. A data source, a template.
<bean id= "DataSource" class= "Com.base.MyDataSource" destroy-method= "Close" >
<property name= "Driverclassname" value= "${database.driverclassname}"/>
<property name= "url" value= "${database.url}"/>
<property name= "username" value= "${database.username}"/>
<property name= "Password" value= "${database.password}"/>
......
<bean id= "JdbcTemplate" class= "Org.springframework.jdbc.core.JdbcTemplate" >
<property name= "DataSource" ref= "DataSource"/>
</bean>
Multiple configurations can be repeated.
The corresponding class is inherited Basicdatasource. and encryption operations are possible.
2, public class.
@Autowired
protected JdbcTemplate JdbcTemplate;
@Autowired
Protected JdbcTemplate JdbcTemplate2;
Annotate multiple template.
3, inherit the public class, you can use the corresponding template database.
Note: In fact, the use of multiple databases is not very reasonable, you should design multiple projects, reduce coupling.
Even if a separate project provides an interface, it is also good and more secure to access only the interface of the project.
Experience summary 45-SPRINGMVC, multiple data sources