1. We usually configure the data source as follows:
<Bean id = "datasource"
Class = "org. Apache. commons. DBCP. basicdatasource">
<Property name = "driverclassname">
<Value> com. Microsoft. JDBC. sqlserver. sqlserverdriver </value>
</Property>
<Property name = "url">
<Value>
JDBC: Microsoft: sqlserver: // Cyc: 1433; databasename = officearticle; selectmethod = cursor
</Value>
</Property>
<Property name = "username">
<Value> SA </value>
</Property>
<Property name = "password">
<Value> SA </value>
</Property>
</Bean>
2. But sometimes I don't want others to know the database username and password through the spring configuration file, which can be achieved by inheriting the basicdatasource.
Package hlkq;
Import org. Apache. commons. DBCP. basicdatasource;
Public class hlkqdatasource extends basicdatasource {
Public hlkqdatasource (){
This. setdriverclassname ("com. Microsoft. JDBC. sqlserver. sqlserverdriver ");
This
. Seturl ("JDBC: Microsoft: SQL SERVER: // localhost: 1433; databasename = qdqt; selectmethod = cursor ");
This. setusername ("sa ");
This. setpassword ("sa ");
}
}
3. Define datasource as follows:
<Bean id = "datasource" class = "hlkq. hlkqdatasource"> </bean>