Spring Configuring JDBC and hibernate data sources

Source: Internet
Author: User
Tags connection pooling

<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>


    1. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.