关闭

JBoss4.0.3+MySQL+Oracle+hibernate

847人阅读 评论(0) 收藏 举报
JBoss是个好东东!不过呀!传说配置资料是要收费的!所以网上很难见到关于一整套的配置过程!
下面是我历经数十文章,百次试验!  从零试到成功!而且还是mysql+Oracle的双数据源。看完后可能认为很简单!呵呵!我配成功后也觉得简单!不过
试验的时候头都快炸了!
有兴趣的朋友可以加我的MSN:china-qianxia@hotmail.com或QQ:55753318 讨论
写于2006.01.20    天夏-商狐-千夏-豪

              
总共三处和五个文件需要配置

一.解压JBoss
进入  JBoss安装目录/bin  
./run.sh  
即可使用!  http://localthost:8080 可以看到控制台

修改  虚拟主机与端口。。和Tomcat一样
在jboss安装目录/server/default/deploy/jbossweb-tomcat55.sar
server.xml 配置。和Tomcat一样。不现详说!

二.配置hibernate
jboss安装目录/server/default/conf下
将Tomcat的hibernate.cfg.xml和hibernatemysql.cfg.xml 拷入即可
附上 hibernate.cfg.xml的 内容:
<?xml version='1.0' encoding='GB2312'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

        <session-factory name="ChinaHouseOracle">
                <property name="connection.datasource">
                        java:/txoracle
                </property>
                <property name="show_sql">true</property>
                <property name="dialect">
                        org.hibernate.dialect.Oracle9Dialect
                </property>

                <!-- mapping -->
           写入你自已的mapping
           </session-factory>

</hibernate-configuration>


配置一样


三.配置数据源
进入jboss目录/server/default/deploy
写入
mysql-ds.xml
内容:
<?xml version="1.0" encoding="UTF-8"?>

<!--  $Id: mysql-ds.xml,v 1.3.2.1 2004/12/01 11:46:00 schrouf Exp  $ -->
<!--  Datasource config for MySQL using 3.0.9 available from:
http://www.mysql.com/downloads/api-jdbc-stable.html
-->

<datasources>
  <local-tx-datasource>
    <jndi-name>txmysql</jndi-name>
    <connection-url>jdbc:mysql://192.168.0.12:3306/txnet?autoReconnect=true&#38;characterEncoding=GB2312</connection-url>
    <driver-class>com.mysql.jdbc.Driver</driver-class>
    <user-name>root</user-name>
    <password></password>
    <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
    <!-- sql to call when connection is created
    <new-connection-sql>some arbitrary sql</new-connection-sql>
      -->
    <!-- sql to call on an existing pooled connection when it is obtained from pool
    <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
      -->

    <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
    <metadata>
       <type-mapping>mySQL</type-mapping>
    </metadata>
  </local-tx-datasource>
</datasources>


写入 oracle-ds.xml
内容:
<?xml version="1.0" encoding="UTF-8"?>

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

<!--  $Id: oracle-ds.xml,v 1.6 2004/09/15 14:37:40 loubyansky Exp  $ -->
<!-- ==================================================================== -->
<!--  Datasource config for Oracle originally from Steven Coy             -->
<!-- ==================================================================== -->


<datasources>
  <local-tx-datasource>
    <jndi-name>txoracle</jndi-name>
    <connection-url>jdbc:oracle:thin:@192.168.0.12:1521:txnet</connection-url>
            <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
    <user-name>txnet</user-name>
    <password>txnet</password>
    <!-- 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>
        <!-- sql to call when connection is created
        <new-connection-sql>some arbitrary sql</new-connection-sql>
        -->

        <!-- sql to call on an existing pooled connection when it is obtained from pool - the OracleValidConnectionChecker is prefered
        <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
        -->

      <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
      <metadata>
         <type-mapping>Oracle9i</type-mapping>
      </metadata>
  </local-tx-datasource>

</datasources>
四.将 war包放入 /server/default/deploy  就可以了!
五.配置完毕!
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:40255次
    • 积分:681
    • 等级:
    • 排名:千里之外
    • 原创:26篇
    • 转载:8篇
    • 译文:0篇
    • 评论:9条
    最新评论
    网址