spring配置链接池: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <!--以连接池方式配置数据源--> <!-- 第一种方式:Apache的DBCP 以SQLServer为例--> <!--需要的jar包:commons-dbcp-1.2.jar;commons-pool-1.3.jar;commons-collections-3.2.jar--> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName"> <value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value> </property> <property name="url"> <value>jdbc:microsoft:sqlserver://ip地址:1433;DatabaseName=testDB</value> </property> <property name="username"> <value>sa</value> </property> <property name="password"> <value>sa</value> </property> <property name="maxActive" /> <value>100</value> </property> <property name="maxIdle" /> <value>20</value> </property> <property name="maxWait" /> <value>10</value> </property> <!--一些其它属性--> </bean> <!--第二种方式:C3P0 以Oracle为例--> <!--需要的jar包:c3p0-0.9.1.jar;--> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass"> <value>oracle.jdbc.driver.OracleDriver</value> </property> <property name="jdbcUrl"> <value>jdbc:oracle:thin:@ip地址:1521:orcl</value> </property> <property name="user"> <value>userName</value> </property> <property name="password"> <value>password</value> </property> <property name="minPoolSize"> <value>5</value> </property> <property name="initialPoolSize"> <value>20</value> </property> <property name="maxIdleTime"> <value>60</value> </property> <property name="acquireIncrement"> <value>5</value> </property> <property name="maxStatements"> <value>0</value> </property> <property name="idleConnectionTestPeriod"> <value>60</value> </property> <property name="acquireRetryAttempts"> <value>30</value> </property> <property name="breakAfterAcquireFailure"> <value>true</value> </property> <property name="testConnectionOnCheckout"> <value>false</value> </property> </bean> <!--第三种方式:JNDI --> <!--需要的jar包:spring-context.jar;--> <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="jdbc/xx" /> <property name="resourceRef" value="false" /> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref local="dataSource" /> </property> <property name="mappingResources"> <list> <value> xx.hbm.xml </value> </list> </property> <property name="hibernateProperties"> <props> <!--部分属性可要可不要--> <!-- server2000 数据 --> <prop key="hibernate.dialect"> org.hibernate.dialect.SQLServerDialect </prop> <!-- oracle数据 --> <!--<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>--> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.cache.provider_class"> org.hibernate.cache.EhCacheProvider </prop> <prop key="hibernate.cache.use_query_cache">true</prop> <prop key="hibernate.query.factory_class"> org.hibernate.hql.ast.ASTQueryTranslatorFactory </prop> <prop key="hibernate.use_sql_comments">true</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.jdbc.batch_size">50</prop> <prop key="hibernate.cache.use_second_level_cache">true</prop> <prop key="hibernate.cache.use_query_cache">true</prop> <prop key="cglib.use_reflection_optimizer">true</prop> </props> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref local="sessionFactory" /> </property> </bean> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate" lazy-init="true"> <property name="sessionFactory"> <ref local="sessionFactory" /> </property> <property name="cacheQueries"> <value>true</value> </property> </bean> </beans> <!-- spring setter注入,获取bean --> <!-- ServletConfig cf = getServletConfig(); --> <!-- ServletContext context = cf.getServletContext(); --> <!-- ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(context); --> <!-- uploadImplDao = (UploadDaoImpl)appContext.getBean("uploadImplDao"); -->