小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

Terasoluna學(xué)習(xí)手記之配置文件applicationContext.xml

 昵稱9376223 2012-04-05

一般而言,Terasoluna特指Terasoluna For Java版。該框架集合了Spring,Struts 1.0以及Ibatis三個(gè)框架,并進(jìn)行了一定程度的擴(kuò)展(如對(duì)輸入文字提交時(shí)進(jìn)行的驗(yàn)證)。該框架進(jìn)一步進(jìn)行了封裝,使得開發(fā)人員更加注重于業(yè)務(wù)邏輯的編寫(Terasoluna中成為Blogic)。

 

applicationContext.xml,全局配置文件。其中包含了

1.Controller的注入,用來(lái)進(jìn)行表單提交時(shí)的攔截,如權(quán)限不夠URL是非法的情形,則會(huì)進(jìn)行錯(cuò)誤的處理。其中需要注入的bean是由開發(fā)者自己實(shí)現(xiàn)的接口jp.terasoluna.fw.web.thin.AuthenticationController。

2.DataSource相關(guān)Bean的注入。若使用WTP模式進(jìn)行DataSource的指定,則需要在META-INF/context.xml中進(jìn)行配置;若使用Tomcat或WebLogic下JDBC的連接方式,則需按一下方式進(jìn)行配置。

<bean id="TerasolunaSampleDataSource"
        class="org.springframework.jndi.JndiObjectFactoryBean">
     <property name="jndiName">
       <!-- Tomcat  -->
       <!--<value>java:comp/env/jdbc/TerasolunaSampleDataSource</value>-->
       <!-- Weblogic  -->
       <!--<value>jdbc/TerasolunaSampleDataSource</value>-->
     </property>
    </bean>

3.事務(wù)管理器的注入。具體參照一下,需要關(guān)聯(lián)DataSource。

// 事務(wù)管理器的創(chuàng)建

<bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource">
            <ref bean="TerasolunaSampleDataSource"/>
        </property>
    </bean>

 

// 對(duì)需要進(jìn)行事務(wù)管理的處理進(jìn)行設(shè)置

<bean id="attrSource"
      class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource">
    <property name="properties">
      <props>
        <prop key="execute*">PROPAGATION_REQUIRED,-java.lang.Exception</prop>
        <prop key="insert*">PROPAGATION_REQUIRED,-java.lang.Exception</prop>
        <prop key="update*">PROPAGATION_REQUIRED,-java.lang.Exception</prop>
        <prop key="delete*">PROPAGATION_REQUIRED,-java.lang.Exception</prop>
        <prop key="select*">PROPAGATION_REQUIRED,readOnly,-java.lang.Exception</prop>
      </props>
    </property>
  </bean>

事務(wù)處理的類是由Spring提供的。

4.事務(wù)管理器攔截設(shè)定。

<bean id="transactionInterceptor"
      class="org.springframework.transaction.interceptor.TransactionInterceptor">
    <property name="transactionManager">
      <ref bean="transactionManager"/>
    </property>
    <property name="transactionAttributeSource">
      <ref local="attrSource"/>
    </property>
  </bean>

 

// 攔截的方法設(shè)定。
  <tx:advice id="transactionInterceptor" >
    <tx:attributes>
      <tx:method name="execute*" propagation="REQUIRED" rollback-for="java.lang.Exception"/>
      <tx:method name="insert*"  propagation="REQUIRED" rollback-for="java.lang.Exception"/>
      <tx:method name="update*"  propagation="REQUIRED" rollback-for="java.lang.Exception"/>
      <tx:method name="delete*"  propagation="REQUIRED" rollback-for="java.lang.Exception"/>
      <tx:method name="select*"  propagation="REQUIRED" rollback-for="java.lang.Exception" read-only="true"/>
    </tx:attributes>
  </tx:advice>

5.輸出日志的設(shè)定。

6.事務(wù)管理的自動(dòng)代理AutoProxy的設(shè)定。

    <bean id="autoProxy"
      class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
      <property name="interceptorNames">
      <list>
        <idref local="transactionInterceptor"/>
      </list>
      </property>
       <property name="beanNames">
         <list>
            <value>*DAO</value>
         </list>
       </property>
    </bean>

7.AOP設(shè)定。

    <aop:config>
        <aop:pointcut id="daoBeans" expression="bean(*DAO)"/>
        <aop:advisor
             pointcut-ref="daoBeans"
             advice-ref="transactionInterceptor"/>
        <aop:advisor
             pointcut-ref="daoBeans"
             advice-ref="debugInterceptor"/>
    </aop:config>

8.Ibatis相關(guān)設(shè)定。

    <bean id="dataSource"
      class="org.apache.commons.dbcp.BasicDataSource"
      destroy-method="close">
      <property name="driverClassName"
       value="oracle.jdbc.OracleDriver" />
      <property name="url"
      value="jdbc:oracle:thin:@172.20.2.53:1521:yum" />
      <property name="username" value="yum" />
      <property name="password" value="yum" />
      <property name="poolPreparedStatements" value="true" />
      <property name="defaultAutoCommit" value="false" />
      <!-- property name="maxActive" ref="threadSize"/ -->
     </bean>
     // Ibatis配置文件

     <bean id="sqlMapClient"
         class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
         <property name="configLocation" value="WEB-INF/sqlMapConfig.xml">
         </property>
         <property name="dataSource">
           <ref bean="dataSource"/>
         </property>
     </bean>

     9.應(yīng)用程序中所常用到的DAO的注入。

     <bean id="queryDAO"
        class="jp.terasoluna.fw.dao.ibatis.QueryDAOiBatisImpl">
        <property name="sqlMapClient"><ref local="sqlMapClient"/></property>
     </bean>
     <bean id="updateDAO"
         class="jp.terasoluna.fw.dao.ibatis.UpdateDAOiBatisImpl">
        <property name="sqlMapClient"><ref local="sqlMapClient"/></property>
     </bean>
     <bean id="spDAO"
         class="jp.terasoluna.fw.dao.ibatis.StoredProcedureDAOiBatisImpl">
        <property name="sqlMapClient"><ref local="sqlMapClient"/></property>
     </bean>

     綜上,applicationContext.xml中配置到的bean全是整個(gè)工程所需要的共通的bean,其實(shí)質(zhì)仍然是一個(gè)Spring的注入配置文件。

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約