JBoss7 Mysql資料來源的建立

來源:互聯網
上載者:User

JBoss7.02 相對JBoss4.2.3 變動較大.原來的-ds.xml 資料來源配置方式 ,貌似已經不行.

以下建立步驟 依賴 mysql-connector-java-5.1.17-bin.jar  ,之前一致用 5.0.1的 包,死活不靈光

1. 建立目錄 

jboss-as-web-7.0.2.Final\modules\com\mysql\main     // "mysql\main"目錄需要手動建立

2. 拷貝mysql-connector-java-5.1.17-bin.jar  到 com\mysql\main\目錄下.

3. com\mysql\main 目錄下 , 建立 modules.xml 

內容:

<?xml version="1.0" encoding="UTF-8"?>   
<module xmlns="urn:jboss:module:1.0" name="com.mysql">
<resources>
<resource-root path="mysql-connector-java-5.1.17-bin.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>

4. 修改設定檔
jboss-as-web-7.0.2.Final\standalone\configuration\standalone.xml

找到以下xml配置節點 ,並新增 加粗部分

<subsystem xmlns="urn:jboss:domain:datasources:1.0">            <datasources>                <datasource jndi-name="java:jboss/datasources/OA_Datasource" pool-name="OA_DS" enabled="true" jta="true" use-java-context="true" use-ccm="true"> <connection-url> jdbc:mysql://localhost:3306/ejbdemo?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&failOverReadOnly=false </connection-url> <driver> mysql </driver> <pool> <min-pool-size> 10 </min-pool-size> <max-pool-size> 100 </max-pool-size> <prefill> true </prefill> <use-strict-min> false </use-strict-min> <flush-strategy> FailingConnectionOnly </flush-strategy> </pool> <security> <user-name> root </user-name> <password> </password> </security> <validation> <validate-on-match> false </validate-on-match> <background-validation> false </background-validation> <use-fast-fail> false </use-fast-fail> </validation> </datasource>                <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="H2DS" enabled="true" jta="true" use-java-context="true" use-ccm="true">                    <connection-url>                        jdbc:h2:mem:test;DB_CLOSE_DELAY=-1                    </connection-url>                    <driver>                        h2                    </driver>                    <pool>                        <prefill>                            false                        </prefill>                        <use-strict-min>                            false                        </use-strict-min>                        <flush-strategy>                            FailingConnectionOnly                        </flush-strategy>                    </pool>                    <security>                        <user-name>                            sa                        </user-name>                        <password>                            sa                        </password>                    </security>                </datasource>                <drivers>                    <driver name="mysql" module="com.mysql"/>                    <driver name="h2" module="com.h2database.h2">                        <xa-datasource-class>                            org.h2.jdbcx.JdbcDataSource                        </xa-datasource-class>                    </driver>                </drivers>            </datasources>        </subsystem>

至於在Jboss Tools 3.3中, 原先的persistence.xml 位置不變,hibernate配置也不變動,如果配置正確,啟動時能看到:

22:29:54,557 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-3) Bound data source [java:jboss/datasources/OA_Datasource]

如果配置了hibernate 自動建表,那麼還可以看見:

 [org.hibernate.tool.hbm2ddl.SchemaExport] (MSC service thread 1-2) HHH00227:Running hbm2ddl schema export
22:29:56,118 INFO  [org.hibernate.tool.hbm2ddl.SchemaExport] (MSC service thread 1-2) HHH00230:Schema export complete

jboss tools 3.3 ,需要eclipse3.7

http://download.jboss.org/jbosstools/updates/development/indigo/

jboss 7.02  Web Profile Only (Java EE6 Certified)
http://download.jboss.org/jbossas/7.0/jboss-as-7.0.2.Final/jboss-as-7.0.2.Final.zip

以上配置,建立 ejb項目成功.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.