JBoss7 Mysql数据源的建立

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项目成功.



你可能感兴趣的:(jboss7)