---
title: "ssh整合主要配置"
author: "Doublecqw"
date: "2011-07-05T21:19:10Z"
tags: []
categories: ["行业应用"]
slug: "ssh"
draft: false
lastmod: "2011-07-05T21:19:10Z"
id: 1115301
url: "https://doublecqw.iteye.com/blog/1115301"
---

cofig.xml  文件

&lt;?xml version="1.0" encoding="UTF-8"?&gt;  
&lt;beans xmlns="[http://www.springframework.org/schema/beans](http://www.springframework.org/schema/beans)"  
xmlns:xsi="[http://www.w3.org/2001/XMLSchema-instance](http://www.w3.org/2001/XMLSchema-instance)"  
xmlns:aop="[http://www.springframework.org/schema/aop](http://www.springframework.org/schema/aop)"  
xmlns:context="[http://www.springframework.org/schema/context](http://www.springframework.org/schema/context)"  
xmlns:tx="[http://www.springframework.org/schema/tx](http://www.springframework.org/schema/tx)"  
xsi:schemaLocation="[http://www.springframework.org/schema/beans](http://www.springframework.org/schema/beans)  
[http://www.springframework.org/schema/beans/spring-beans-2.5.xsd](http://www.springframework.org/schema/beans/spring-beans-2.5.xsd)  
[http://www.springframework.org/schema/aop](http://www.springframework.org/schema/aop)  
[http://www.springframework.org/schema/aop/spring-aop-2.5.xsd](http://www.springframework.org/schema/aop/spring-aop-2.5.xsd)  
[http://www.springframework.org/schema/context](http://www.springframework.org/schema/context)  
[http://www.springframework.org/schema/context/spring-context-2.5.xsd](http://www.springframework.org/schema/context/spring-context-2.5.xsd)  
[http://www.springframework.org/schema/tx](http://www.springframework.org/schema/tx)  
[http://www.springframework.org/schema/tx/spring-tx-2.5.xsd](http://www.springframework.org/schema/tx/spring-tx-2.5.xsd) "&gt;  
            
            
&lt;!-- 数据库连接池 --&gt;  
 &lt;bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"  
  destroy-method="close"&gt;  
  &lt;property name="driverClass" value="${jdbc.driverClass}" /&gt;  
  &lt;property name="jdbcUrl" value="${jdbc.url}" /&gt;  
  &lt;property name="user" value="${jdbc.user}" /&gt;  
  &lt;property name="password" value="${jdbc.password}" /&gt;  
  &lt;!--初始化时获取的连接数，取值应在minPoolSize与maxPoolSize之间。Default: 3 --&gt;  
  &lt;property name="initialPoolSize" value="1" /&gt;  
  &lt;!--连接池中保留的最小连接数。--&gt;  
  &lt;property name="minPoolSize" value="1" /&gt;  
  &lt;!--连接池中保留的最大连接数。Default: 15 --&gt;  
  &lt;property name="maxPoolSize" value="300" /&gt;  
  &lt;!--最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 --&gt;  
  &lt;property name="maxIdleTime" value="60" /&gt;  
  &lt;!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 --&gt;  
  &lt;property name="acquireIncrement" value="5" /&gt;  
  &lt;!--每60秒检查所有连接池中的空闲连接。Default: 0 --&gt;  
  &lt;property name="idleConnectionTestPeriod" value="60" /&gt;  
 &lt;/bean&gt;

 &lt;bean id="sessionFactory"  
  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt;  
  &lt;!-- dataSource配置 --&gt;  
  &lt;property name="dataSource" ref="dataSource" /&gt;  
  &lt;!-- 引入映射文件.hbm.xml --&gt;  
  &lt;property name="mappingResources"&gt;  
   &lt;list&gt;  
    &lt;value&gt;cn/shopping/domain/Customers.hbm.xml&lt;/value&gt;  
    &lt;value&gt;cn/shopping/domain/Employees.hbm.xml&lt;/value&gt;  
    &lt;value&gt;cn/shopping/domain/Goods.hbm.xml&lt;/value&gt;  
    &lt;value&gt;cn/shopping/domain/Message.hbm.xml&lt;/value&gt;  
    &lt;value&gt;cn/shopping/domain/Orderdetails.hbm.xml&lt;/value&gt;  
    &lt;value&gt;cn/shopping/domain/Orders.hbm.xml&lt;/value&gt;  
    &lt;value&gt;cn/shopping/domain/Payments.hbm.xml&lt;/value&gt;  
    &lt;value&gt;cn/shopping/domain/Types.hbm.xml&lt;/value&gt;  
    &lt;value&gt;cn/shopping/domain/Users.hbm.xml&lt;/value&gt;  
   &lt;/list&gt;  
  &lt;/property&gt;  
  &lt;!-- hiberante属性的配置 --&gt;  
  &lt;property name="hibernateProperties"&gt;  
   &lt;props&gt;  
    &lt;prop key="hibernate.dialect"&gt;${hibernate.dialect}&lt;/prop&gt;  
    &lt;prop key="hibernate.hbm2ddl.auto"&gt;${hibernate.hbm2ddl.auto}&lt;/prop&gt;  
    &lt;prop key="hibernate.show\_sql"&gt;${hibernate.show\_sql}&lt;/prop&gt;  
    &lt;prop key="hibernate.format\_sql"&gt;${hibernate.format\_sql}&lt;/prop&gt;  
   &lt;/props&gt;  
  &lt;/property&gt;  
 &lt;/bean&gt;

 &lt;!-- 分散配置信息 --&gt;  
 &lt;bean id="propertyPlaceholderConfigurer"  
  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;  
  &lt;property name="locations"&gt;  
   &lt;list&gt;  
    &lt;value&gt;classpath:cn/shopping/config/jdbc.properties&lt;/value&gt;  
   &lt;/list&gt;  
  &lt;/property&gt;  
 &lt;/bean&gt;  
   
 &lt;!-- 用注解管理事务 --&gt;  
  &lt;!--  
 spring默认的注入为接口注入方式。如果我们想用实现类进行注入，需要做两方面的工作：  
1、导入CGLIB库，即cglib.jar包  
2、在spring配置文件applicationContext.xml中进行一下配置：&lt;aop:aspectj-autoproxy proxy-target-class="true"/&gt;  
 --&gt;  
   
 &lt;aop:aspectj-autoproxy proxy-target-class="true"/&gt;  
 &lt;!-- 设定transactionManager --&gt;  
   &lt;bean id="transactionManager"  
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager"&gt;  
    &lt;property name="dataSource" ref="dataSource" /&gt;  
   &lt;/bean&gt;  
   
 &lt;!--启动spring注解功能--&gt;  
 &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;

   
   
&lt;/beans&gt;

 

jdbc.properties 资源文件

hibernate.dialect=org.hibernate.dialect.MySQL5Dialect  
hibernate.hbm2ddl.auto=update  
hibernate.show\_sql=true  
hibernate.format\_sql=false  
jdbc.driverClass=com.mysql.jdbc.Driver  
jdbc.url=jdbc\\:mysql\\://localhost\\:3306/btocshopping?useUnicode\\=true&characterEncoding\\=UTF-8  
jdbc.user=root  
jdbc.password=123

用到的jar包自己可以上网找