application.xml

SSH环境下的applicationContext.xml  2010-03-25 11:35:10|  分类: SSH整合框架 |  标签: |字号大

小 订阅
<?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"
  class="【自定义的源配置文件……com.yuanchung.saas.SwitcherDataSource】">
  <property name="dataSource">
   <ref bean="default_data_source" />
  </property>
</bean>

<bean id="default_data_source"
  class="com.mchange.v2.c3p0.ComboPooledDataSource"
  destroy-method="close">
  <property name="jdbcUrl"
   value="jdbc:mysql://192.168.1.131:3306/common" />
  <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"
  class="com.mchange.v2.c3p0.ComboPooledDataSource"
  destroy-method="close">
  <property name="jdbcUrl"
   value="jdbc:mysql://localhost:3306/page" />
  <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"
  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="dataSource">
   <ref bean="dataSource" />
  </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"
  class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <!-- 为事务管理器注入sessionFactory" -->
  <property name="sessionFactory" ref="sessionFactory" />
</bean>

<!-- 事物管理方法1 -->
<!-- 配置事务注解驱动 -->
<tx:annotation-driven transaction-manager="transactionManager" />
<!-- 配置事务拦截器Bean -->
<bean id="transactionInterceptor"
  class="org.springframework.transaction.interceptor.TransactionInterceptor">
  <!-- 为事务拦截器bean注入一个事物管理器 -->
  <property name="transactionManager" 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"
  class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
  <!-- 指定哪些bean需要自动创建业务代理 -->
  <property name="beanNames">
   <list>
    <value>CustomerMgr</value>
    <value>TaskEventMgr</value>
    <value>UserMgr</value>
   </list>
  </property>
  <!-- 注入事务代理所需要的拦截器 -->
  <property name="interceptorNames">
   <list>
    <value>transactionInterceptor</value>
   </list>
  </property>
</bean>

<!-- 配置权限拦截器 -->
<bean id="authorityInterceptor"
  class="com.yuanchung.sales.struts.authority.AuthorityInterceptor">
</bean>
<bean
  class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
  <property name="beanNames">
   <list>
    <value>/customer</value>
    <value>/contact</value>
    <value>/busiOpport</value>
    <value>/admin/user</value>
   </list>
  </property>
  <property name="interceptorNames">
   <list>
    <value>authorityInterceptor</value>
   </list>
  </property>
</bean>


<!-- 配置事务切面 -->
<aop:config>
  <!-- 定义切入点:com.zzy.zdms.service包及其子包中定义的任意方法的执行 -->
  <!-- <aop:advisor pointcut="execution(*com.zzy.zdms.service..*.*(..))" 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"
  class="com.crm.dao.customer.impl.CustomerDAOImpl">
  <property name="sessionFactory">
   <ref bean="sessionFactory" />
  </property>
</bean>

<bean id="CustomerMgr"
  class="com.crm.service.customer.impl.CustomerMgrImpl">
  <property name="customerDAO">
   <ref bean="CustomerDAO" />
  </property>
  <property name="productDAO">
   <ref bean="ProductDAO" />
  </property>
</bean>

<bean name="/customer"
  class="com.crm.struts.customer.action.CustomerAction">
  <property name="customerMgr">
   <ref bean="CustomerMgr" />
  </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" />


猜你喜欢

转载自zhaoyanss.iteye.com/blog/1139862
今日推荐