使用EJB使用jboss7.0中配置資料來源

來源:互聯網
上載者:User

標籤:jboss   ejb   

使用EJB時需要配置資料來源,光在代碼裡面添加配置是不夠的,還需要在jboss中配置
首先在jboss-as-web-7.0.2.Final\standalone\configuration目錄下standalone.xml中<datasources>標籤中添加你的資料來源配置:
這裡drivername是mysql

<datasource jndi-name="java:jboss/datasources/localTrans/FirstTest" pool-name="localTrans_FirstTest" enabled="true" jta="true" use-java-context="true" use-ccm="true">                    <connection-url>                        jdbc:mysql://127.0.0.1:3306/jsftest                    </connection-url>                    <connection-property name="zeroDateTimeBehavior">                        round                    </connection-property>                    <connection-property name="connectTimeout">                        180000                    </connection-property>                    <connection-property name="socketTimeout">                        180000                    </connection-property>                    <connection-property name="characterEncoding">                        UTF-8                    </connection-property>                    <connection-property name="autoReconnectForPools">                        true                    </connection-property>                    <driver>                        mysql                    </driver>                    <pool>                        <min-pool-size>                            0                        </min-pool-size>                        <max-pool-size>                            50                        </max-pool-size>                        <prefill>                            false                        </prefill>                        <use-strict-min>                            false                        </use-strict-min>                        <flush-strategy>                            EntirePool                        </flush-strategy>                    </pool>                    <security>                        <user-name>                            root                        </user-name>                        <password>                            root                        </password>                    </security>                    <validation>                        <check-valid-connection-sql>                            select 1                        </check-valid-connection-sql>                        <validate-on-match>                            false                        </validate-on-match>                        <background-validation>                            true                        </background-validation>                        <background-validation-millis>                            1800000                        </background-validation-millis>                        <use-fast-fail>                            false                        </use-fast-fail>                    </validation>                    <timeout>                        <idle-timeout-minutes>                            5                        </idle-timeout-minutes>                        <query-timeout>                            120                        </query-timeout>                    </timeout>                    <statement>                        <track-statements>                            TRUE                        </track-statements>                        <prepared-statement-cache-size>                            100                        </prepared-statement-cache-size>                        <share-prepared-statements/>                    </statement>                </datasource>

添加<drivers>下添加driver:

<driver name="mysql" module="com.mysql"/>

然後在modules\com檔案夾下建立mysql\main檔案夾
main裡面添加驅動jar包以及module.xml檔案:
path為jar包名,name為上面的module值
這一段可以把modules\com\h2database\h2\main中的module.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.21-bin.jar"/>        <!-- Insert resources here -->  </resources>  <dependencies>    <module name="javax.api"/>    <module name="javax.transaction.api"/>  </dependencies></module>

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

使用EJB使用jboss7.0中配置資料來源

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.