SSH环境下的applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<!-- 配置注解 -->
<context:annotation-config />
<!-- 配置数据源 -->
【如果需要配置多个数据源的时候,可以如下配置,需要建立一个SwitcherDataSource类】
<bean id="dataSource"
/>
</property>
</bean>
<bean id="default_data_source"
/>
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="user" value="root"></property>
<property name="password" value="123456"></property>
<property name="maxPoolSize" value="40" />
<property name="minPoolSize" value="1" />
<property name="initialPoolSize" value="1" />
<property name="maxIdleTime" value="20" />
</bean>
【如果需要配置多个数据源的时候,可以如下配置】
<bean id="dataSource"
/>
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="user" value="root"></property>
<property name="password" value=""></property>
<property name="maxPoolSize" value="40" />
<property name="minPoolSize" value="1" />
<property name="initialPoolSize" value="1" />
<property name="maxIdleTime" value="20" />
</bean>
<!-- 配置sessionFactory -->
<bean id="sessionFactory"
/>
</property>
<property name="hibernateProperties">
<props>
<!-- 数据库方言 -->
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.jdbc.batch_size">20</prop>
<prop key="hibernate.connection.autocommit">true</prop>
<!-- 显示sql语句 -->
<prop key="hibernate.show_sql">true</prop>
<!--解决hql中文问题 -->
<prop key="hibernate.connection.useUnicode">true</prop>
<prop key="hibernate.connection.characterEncoding">
UTF-8
</prop>
<!-- hibernate缓存设置 -->
<prop key="hibernate.cache.use_second_level_cache">
true
</prop>
<prop key="hibernate.cache.provider_class">
org.hibernate.cache.EhCacheProvider
</prop>
<prop key="hibernate.cache.use_query_cache">false</prop>
<!-- 创建表 -->
<prop key="hibernate.hbm2ddl.auto">update</prop>
<!-- 缓存路径 -->
【当使用二级缓存的时候,需要标配缓存路径】
<prop key="net.sf.ehcache.configurationResourceName">
classpath:ehcache.xml
</prop>
【当使用二级缓存的时候,需要标配缓存路径】
</props>
</property>
【映射文件配置】
<property name="mappingResources">
<list>
<value>com/crm/model/customer/Customer.hbm.xml</value>
<value>com/crm/model/product/Product.hbm.xml</value>
<value>com/crm/model/order/Order.hbm.xml</value>
<value>com/crm/model/visualOrder/VisualOrder.hbm.xml</value>
</list>
</property>
</bean>
<!-- 配置事务管理器bean,使用HibernateTransactionManager事务管理器 -->
<bean id="transactionManager"
-->
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 事物管理方法1 -->
<!-- 配置事务注解驱动 -->
<tx:annotation-driven transaction-manager="transactionManager" />
<!-- 配置事务拦截器Bean -->
<bean id="transactionInterceptor"
ref="transactionManager"></property>
<property name="transactionAttributes">
<!-- 定义事务传播属性 -->
<props>
<prop key="insert*">
PROPAGATION_REQUIRED,-Exception
</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="modify*">PROPAGATION_REQUIRED</prop>
<prop key="merge*">PROPAGATION_REQUIRED</prop>
<prop key="edit*">PROPAGATION_REQUIRED</prop>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="add*">PROPAGATION_REQUIRED</prop>
<prop key="new*">PROPAGATION_REQUIRED</prop>
<prop key="remove*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="del*">PROPAGATION_REQUIRED</prop>
<prop key="authorization*">PROPAGATION_REQUIRED</prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="search*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="change*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="set*">PROPAGATION_REQUIRED</prop>
<prop key="getCustomerByOption">PROPAGATION_REQUIRED</prop>
<prop key="getCustomerAll">PROPAGATION_REQUIRED</prop>
<prop key="getReportData">PROPAGATION_REQUIRED</prop>
<prop key="getMyCustomer">PROPAGATION_REQUIRED</prop>
<prop key="getShareCustomer">PROPAGATION_REQUIRED</prop>
<prop key="getPublicCustomer">PROPAGATION_REQUIRED</prop>
<prop key="share*">PROPAGATION_REQUIRED</prop>
<prop key="getWapMyCustomer">PROPAGATION_REQUIRED</prop>
<prop key="getWapShareCustomer">PROPAGATION_REQUIRED</prop>
<prop key="getWapPublicCustomer">PROPAGATION_REQUIRED</prop>
<prop key="getContactByOptionId">PROPAGATION_REQUIRED</prop>
<prop key="getBusiOpportByOptionId">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<!-- 事物管理方法2 -->
<!-- 配置事务通知属性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<!-- 定义事务传播属性 -->
<tx:attributes>
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="edit*" propagation="REQUIRED" />
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="new*" propagation="REQUIRED" />
<tx:method name="set*" propagation="REQUIRED" />
<tx:method name="remove*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="change*" propagation="REQUIRED" />
<tx:method name="modify*" propagation="REQUIRED" />
<tx:method name="get*" propagation="REQUIRED"
read-only="true" />
<tx:method name="find*" propagation="REQUIRED"
read-only="true" />
<tx:method name="load*" propagation="REQUIRED"
read-only="true" />
<tx:method name="query*" propagation="REQUIRED"
read-only="true" />
<tx:method name="is*" propagation="REQUIRED"
read-only="true" />
<tx:method name="look*" propagation="REQUIRED"
read-only="true" />
<tx:method name="search*" propagation="REQUIRED"
read-only="true" />
<tx:method name="view*" propagation="REQUIRED"
read-only="true" />
<tx:method name="*" propagation="REQUIRED" read-only="true" />
</tx:attributes>
</tx:advice>
<!-- 配置事务代理 -->
<bean id="beanProxy"
advice-ref="txAdvice"/> -->
<aop:pointcut id="serviceOperation"
expression="execution(* com.yuorCompany.C3p0.service..*.*(..))" />
<aop:advisor advice-ref="txAdvice"
pointcut-ref="serviceOperation" />
</aop:config>
【DAO、业务层和实现层的配置】
<bean id="CustomerDAO"
/>
</property>
</bean>
<bean id="CustomerMgr"
/>
</property>
<property name="productDAO">
<ref bean="ProductDAO" />
</property>
</bean>
<bean name="/customer"
/>
</property>
<property name="productMgr">
<ref bean="ProductMgr" />
</property>
</bean>
</beans>
【…………有多个开发人员参与的时候,如果在web.xml中没有配置多个applicationContext.xml,需要在applicationContext.xml文件中加入以下配置…………】
<!-- 加载xml文件 -->
<import resource="applicationContext-yang.xml" />
<import resource="applicationContext-wyl.xml" />