<bean id= "DataSource" class= "Org.apache.commons.dbcp.BasicDataSource" destroy-method= "Close" > <property name= "Driverclassname" value= " Oracle.jdbc.driver.OracleDriver "/> <property name=" url " Value= "Jdbc:oracle:thin: @localhost: 1521:orcl"/> <property name= " Username " value=" bam1 "/> <property name=" password " Value= "bam1"/> <!-- Initial value when connection pooling starts --> <property name= "InitialSize" value= "1"/> <!-- Maximum value of connection pool --> <property name= " Maxactive "value="/> <!-- Maximum idle value. After a peak time, the connection pool can slowly release a portion of the connection that has not been used, and has been reduced to maxidle until --> <property name= "Maxidle" value= "2"/> <!-- Minimum idle value. When the number of idle connections is less than the threshold, the connection pool will pre-request some connections to avoid the performance overhead of applying the flood peak time --> <property name= "Minidle" value= "1"/> </bean> The spring container provides us with an auxiliary class specifically for JDBC operations, which requires injecting a data source object into the JDBC helper class, adding the following code to the XML file: <bean id= "jdbc" class= "Org.springframework.jdbc.core.JdbcTemplate" > <constructor-arg ref= "DataSource" ></constructor-arg> //injecting a data source object requires a method injection using a constructor, and a third-party class needs to be injected manually </bean>
Get the JdbcTemplate object for additional pruning and checking.
<!--get return Sessionfactory object--><bean id= "Sessionfactory" class= " Org.springframework.orm.hibernate3.LocalSessionFactoryBean "><property name=" configlocation "value=" Classpath:hibernate.cfg.xml "></property></bean>
The 2.DAO class inherits Hibernatedaosupport and then injects the Sessionfactory object to get the Hibernatetemplate object for additional pruning and checking.
3. Complete your own Write DAO and then rely only on spring's bean management to inject DAO for sevice control.
Spring Configuring JDBC and hibernate data sources