搭建SSH框架


org.springframework.web.context.ContextLoaderListener;
org.springframework.web.context.ContextLoaderServlet;
org.springframework.web.struts.DelegatingActionProxy;
org.springframework.web.struts.ContextLoaderPlugIn;
org.apache.commons.dbcp.BasicDataSource;
org.springframework.orm.hibernate3.LocalSessionFactoryBean;
org.springframework.orm.hibernate3.HibernateTransactionManager;
org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator;
org.springframework.orm.hibernate3.HibernateInterceptor;
org.springframework.transaction.interceptor.TransactionInterceptor;

<!--  添加spring插件到Struts-config.xml中,在struts中加载applicationContext.xml文件-->
  <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
     <set-property property="contextConfigLocation"
        value="/WEB-INF/applicationContext.xml" />
  </plug-in>

<bean id="datasource"
  class="org.apache.commons.dbcp.BasicDataSource"
  destroy-method="close">
  <property name="driverClassName">
   <value>com.microsoft.sqlserver.jdbc.SQLServerDriver</value>
  </property>
  <property name="url">
   <value>jdbc:sqlserver://localhost:1433;dataBaseName=BBS</value>
  </property>
  <property name="username">
   <value>sa</value>
  </property>
  <property name="password">
   <value>accp</value>
  </property>
 </bean>
 <bean id="sessionFactory"
  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="configLocation"
   value="classpath:hibernate.cfg.xml">
  </property>
  <property name="dataSource">
   <ref bean="datasource" />
  </property>
 </bean>

<!--    事务管理器-->
    <bean id="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory">
          <ref local="sessionFactory" />
        </property>
    </bean>    
   
    <bean id="DAOBeanNameAutoProxyCreator"
  class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
  <property name="beanNames">
   <value>*Impl,*Service</value>
  </property>
  <property name="interceptorNames">
   <list>
    <value>DAOInterceptor</value>
    <value>hibernateInterceptor</value>
   </list>
  </property>
 </bean>
 <!-- 自动代理生成结束-->
 <!-- aop拦截取代template-->

 <bean id="hibernateInterceptor"
  class="org.springframework.orm.hibernate3.HibernateInterceptor">
  <property name="sessionFactory">
   <ref bean="sessionFactory" />
  </property>
 </bean>
 <!-- aop拦截取代template结束-->
 <bean id="DAOInterceptor"
  class="org.springframework.transaction.interceptor.TransactionInterceptor">
  <property name="transactionManager">
   <ref bean="transactionManager" />
  </property>
  <property name="transactionAttributes">
   <props>
   <prop key="*">PROPAGATION_REQUIRED</prop>
   </props>
  </property>
 </bean>
事务或者采用
<bean id="BasicTransactionProxy" abstract="true"
       class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
        <property name="transactionManager">
            <ref bean="transactionManager" />
        </property>
       策略
        <property name="transactionAttributes">
           <props>
              这里的方法签名可以精确到方法
              <prop key="save*">PROPAGATION_REQUIRED</prop>
              <prop key="update*">PROPAGATION_REQUIRED</prop>
              <prop key="del*">PROPAGATION_REQUIRED</prop>
              <prop key="add*">PROPAGATION_REQUIRED</prop>
              <prop key="do*">PROPAGATION_REQUIRED</prop>
              <prop key="*">PROPAGATION_REQUIRED</prop>
           </props>
        </property>
    </bean>
    业务代理类
    <bean id="UserImplProxy" parent="BasicTransactionProxy">
       <property name="target">
         <ref bean="UserImpl"/>
       </property>
    </bean>
   

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值