JBoss+Spring+Oracle+JTA的设置方法

一、配置数据源
    拷贝%JBOSS_HOW%doc/examples/jca/oracle-xa-ds.xml%JBOSS_HOW%server/default/deploy目录下修改其中的设置:
    <?xml version="1.0" encoding="UTF-8"?>

    <!-- ===================================================================== -->
    <!--                                                                       -->
    <!--  JBoss Server Configuration                                           -->
    <!--                                                                       -->
    <!-- ===================================================================== -->

    <!-- $Id: oracle-xa-ds.xml 23720 2004-09-15 14:37:40Z loubyansky $ -->

    <!-- ===================================================================== -->
    <!-- ATTENTION:  DO NOT FORGET TO SET Pad=true IN transaction-service.xml  -->
    <!-- ===================================================================== -->

    <datasources>
      <xa-datasource>
        <jndi-name>XADS/SecurityCenter</jndi-name>
        <track-connection-by-tx/>
        <isSameRM-override-value>false</isSameRM-override-value>
        <xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
        <xa-datasource-property name="URL">jdbc:oracle:thin:@172.60.8.15:1522:dcscdb</xa-datasource-property>
        <xa-datasource-property name="User">dcsc</xa-datasource-property>
        <xa-datasource-property name="Password">dcsc</xa-datasource-property>
        <!-- Uses the pingDatabase method to check a connection is still valid before handing it out from the pool -->
        <!--valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker</valid-connection-checker-class-name-->
        <!-- Checks the Oracle error codes and messages for fatal errors -->
        <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
        <!-- Oracles XA datasource cannot reuse a connection outside a transaction once enlisted in a global transaction and vice-versa -->
        <no-tx-separate-pools/>

          <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
          <metadata>
             <type-mapping>Oracle10g</type-mapping>
          </metadata>
      </xa-datasource>

      <mbean code="org.jboss.resource.adapter.jdbc.vendor.OracleXAExceptionFormatter"
             name="jboss.jca:service=OracleXAExceptionFormatter">
        <depends optional-attribute-name="TransactionManagerService">jboss:service=TransactionManager</depends>
      </mbean>

    </datasources>
二、配置XidFactory
    修改%JBOSS_HOW%server/default/conf/jboss-server.xml中的XidFactory的设定:
    <mbean code="org.jboss.tm.XidFactory"
      name="jboss:service=XidFactory">
      <attribute name="Pad">true</attribute>
   </mbean>
三、拷贝JDBC驱动
    将Oracle的JDBC驱动classes12.jar拷入%JBOSS_HOW%server/default/lib中
四、配置Spring
    <?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:util="http://www.springframework.org/schema/util"
        xmlns:lang="http://www.springframework.org/schema/lang"
        xmlns:aop="http://www.springframework.org/schema/aop"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xmlns:jee="http://www.springframework.org/schema/jee"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
        http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.0.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd">
       
        <!-- サーバ用メッセージ -->
        <bean id="messageResource" class="jp.co.ntt.dc.framework.common.msg.MessageResource" />
        <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
            <property name="useCodeAsDefaultMessage" value="true" />
            <property name="basenames">
                <list>
                    <value>messages</value>
                    <value>common-messages</value>
                </list>
            </property>
        </bean>

        <!-- システム設定 -->
        <bean id="globalProperty" class="jp.co.ntt.dc.framework.server.common.GlobalProperties"
            factory-method="getInstance">
            <property name="operator">
                <bean class="jp.co.ntt.dc.framework.server.common.SystemPropertiesOperator" parent="daoBase" />
            </property>
        </bean>
        <!-- システム設定用DAO -->
        <bean name="propertiesOperator" class="jp.co.ntt.dc.framework.server.common.SystemPropertiesOperator"
            parent="daoBase" />

        <!-- SQLリソース -->
        <bean id="sqlResource" class="jp.co.ntt.dc.framework.server.config.SQLResource" init-method="init">
            <property name="locations">
                <list>
                    <value>classpath:fw.hql.xml</value>
                    <value>classpath:equip.hql.xml</value>
                    <value>classpath:filter.hql.xml</value>
                    <value>classpath:job.hql.xml</value>
                    <value>classpath:kdm.hql.xml</value>
                    <value>classpath:key.hql.xml</value>
                    <value>classpath:license.hql.xml</value>
                    <value>classpath:log.hql.xml</value>
                    <value>classpath:manage.hql.xml</value>
                    <value>classpath:master.hql.xml</value>
                    <value>classpath:theater.hql.xml</value>
                    <value>classpath:theaterstatus.hql.xml</value>
                    <value>classpath:common.hql.xml</value>
                    <value>classpath:sequence.hql.xml</value>
                </list>
            </property>
        </bean>

        <!-- フレームワーク用設定 -->
        <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="locations">
                <list>
                    <value>classpath:system.properties</value>
                </list>
            </property>
        </bean>

        <!-- データソースの設定 -->
        <jee:jndi-lookup id="dataSource" jndi-name="java:XADS/SecurityCenter"/>

        <!-- Hibernate SessionFactory -->
        <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            <property name="dataSource" ref="dataSource" />
            <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                    <prop key="hibernate.show_sql">true</prop>
                </props>
            </property>

            <!-- Must references all OR mapping files.-->
            <property name="mappingResources">
                <list>
                    <value>common.xml</value>
                    <value>securityCenter.xml</value>
                </list>
            </property>
        </bean>

        <!-- トランザクションの設定 -->
        <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager" />
        <tx:advice id="transactionAdvice" transaction-manager="transactionManager">
            <tx:attributes>
                <tx:method name="execute" />
                <tx:method name="send" />
            </tx:attributes>
        </tx:advice>

        <!-- トランザクション用AOPの設定 -->
        <aop:config>
            <aop:pointcut id="businessLogic"
                expression="execution(* jp.co.ntt.dc.framework.server.action.IActionBase.execute(..))" />
            <aop:advisor advice-ref="transactionAdvice" pointcut-ref="businessLogic" />
        </aop:config>

        <!-- DBアクセスヘルプ -->
        <bean id="dbHelper" class="jp.co.ntt.dc.framework.server.dao.DBAccessHelper">
            <property name="sessionFactory" ref="sessionFactory" />
        </bean>

        <!-- DAOの親クラス -->
        <bean id="daoBase" class="jp.co.ntt.dc.framework.server.dao.IDaoBase" abstract="true">
            <property name="dbHelper" ref="dbHelper" />
        </bean>

        <!-- Actionの親クラス -->
        <bean id="actionBase" class="jp.co.ntt.dc.framework.server.action.IActionBase" abstract="true">
            <property name="daoMap">
                <map>
                    <entry key="masterDAO">
                        <ref bean="masterDAO" />
                    </entry>
                    <entry key="CommonDAO">
                        <ref bean="CommonDAO" />
                    </entry>
                </map>
            </property>
        </bean>

        <!-- マスタテーブル用DAO -->
        <bean name="masterDAO" class="jp.co.ntt.dc.business.server.sc.common.dao.MasterDao" parent="daoBase" />

        <!-- システム共通DAO -->
        <bean name="CommonDAO" class="jp.co.ntt.dc.framework.server.dao.CommonDao" parent="daoBase" />

        <!-- Validateアクション -->
        <bean name="/ActionValidate" class="jp.co.ntt.dc.framework.server.action.ActionValidate" init-method="init">
            <property name="actionValidateDAO">
                <ref bean="actionValidateDAO" />
            </property>
        </bean>
        <!-- Validateアクション用のDAO -->
        <bean name="actionValidateDAO" class="jp.co.ntt.dc.framework.server.dao.ActionValidateDao" parent="daoBase" />

        <!-- RMIのサービス -->
        <bean name="remotingService" class="jp.co.ntt.dc.framework.server.handler.RemotingController">
            <property name="handlerMapping" ref="remotingMapping" />
        </bean>
        <!-- RMI Mapping -->
        <bean name="remotingMapping" class="jp.co.ntt.dc.framework.server.handler.HandlerMapping" />
        <!-- アクションの自動登録Bean -->
        <bean class="jp.co.ntt.dc.framework.server.handler.ActionBeanAutoRegistrant">
            <property name="handlerMapping" ref="remotingMapping" />
        </bean>
        <!-- RMIのインタフェース -->
        <bean name="/RemotingService" class="jp.co.ntt.dc.framework.server.handler.CenterAppHttpInvokerServiceExporter">
            <property name="service" ref="remotingService" />
            <property name="serviceInterface" value="jp.co.ntt.dc.framework.common.service.IRemotingService" />
        </bean>

        <!-- **Http Invokers Client** -->
        <!-- **Http Invokers FactoryBean** -->
        <bean id="remotingFactoryBean" class="jp.co.ntt.dc.framework.common.remoting.DCHttpInvokerProxyFactoryBean">
            <property name="serviceUrl"
                value="http://${server.ip}:${server.port}/${server.module}/${server.service.remoting}" />
            <property name="serviceInterface" value="jp.co.ntt.dc.framework.common.service.IRemotingService" />
        </bean>

        <!-- **Http Invokers RemotingProxy** -->
        <bean id="remotingProxy" class="jp.co.ntt.dc.framework.server.remoting.RemotingProxy">
            <property name="remotingFactoryBean" ref="remotingFactoryBean" />
            <property name="context" ref="context" />
        </bean>

        <!-- **Http Invokers Client Helper** -->
        <bean id="remotingHelper" class="jp.co.ntt.dc.framework.server.remoting.RemotingHelper">
            <property name="remotingProxy" ref="remotingProxy" />
        </bean>

        <!-- **Context** -->
        <bean id="context" class="jp.co.ntt.dc.framework.server.context.DCContext">
            <property name="defaultUserId" value="${default.userid}" />
            <property name="defaultUserPswd" value="${default.password}" />
            <property name="jndiMap">
                <map>
                    <entry key="java.naming.factory.initial" value="${java.naming.factory.initial}" />
                    <entry key="java.naming.factory.url.pkgs" value="${java.naming.factory.url.pkgs}" />
                    <entry key="java.naming.provider.url" value="${java.naming.provider.url}" />
                </map>
            </property>
        </bean>

    </beans>
五、疑难杂症
    java.lang.IllegalStateException: Either 'userTransaction' or 'userTransactionName' or 'transactionManager' or 'transactionManagerName' must be specified
是因为运用的lib中jbossall-cient.jar、jta.jar、servlet.jar删除(搞死我了,一天就耗在这里面)。

你可能感兴趣的:(spring,oracle,bean,jboss,Class,attributes)