jboss-eap-6.2 JNDI配置数据源Oracle&sql server

jboss-eap-6.2 JNDI配置数据源Oracle&sql server

  • Oracle数据源
  1. 创建模块,jboss-eap-6.2\modules\system\layers\base目录下,创建目录com\oracle\main
  2. 拷贝ojdbc14-10.2.0.4.0.jar和module.xml

module.xml

<?xml version="1.0" encoding="UTF-8"?>  
<module xmlns="urn:jboss:module:1.1" name="com.oracle">  
    <properties>  
        <property name="jboss.api" value="public"/>  
    </properties>  
    <resources>  
        <resource-root path="ojdbc14-10.2.0.4.0.jar"/>  
        <!-- Insert resources here -->  
    </resources>  
    <dependencies>  
        <module name="javax.api"/>  
        <module name="javax.transaction.api"/>  
        <module name="javax.servlet.api" optional="true"/>  
    </dependencies>  
</module>  
  1. 修改jboss-eap-6.2\standalone\configuration\standalone.xml

standalone.xml

<datasource jta="true" jndi-name="java:jboss/datasources/OracleDS" pool-name="OracleDS" enabled="true" use-java-context="true">
    <connection-url>jdbc:oracle:thin:@127.0.0.1:1521:ORCL</connection-url>
    <driver>oracle</driver>
    <pool>
        <prefill>false</prefill>
        <use-strict-min>false</use-strict-min>
        <flush-strategy>FailingConnectionOnly</flush-strategy>
    </pool>
    <security>
        <user-name>rick</user-name>
        <password>jkxyx205</password>
    </security>
</datasource>
<driver name="oracle" module="com.oracle">
    <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
</driver>
  • sql server数据源同上,仅给出配置文件sql server

module.xml

<?xml version="1.0" encoding="UTF-8"?>  
<module xmlns="urn:jboss:module:1.1" name="com.microsoft.sqlserver.jdbc">  
    <properties>  
        <property name="jboss.api" value="public"/>  
    </properties>  
    <resources>  
        <resource-root path="sqljdbc4.jar"/>  
        <!-- Insert resources here -->  
    </resources>  
    <dependencies>  
        <module name="javax.api"/>  
        <module name="javax.transaction.api"/>  
        <module name="javax.servlet.api" optional="true"/>  
    </dependencies>  
</module>  
<driver name="sqlserver" module="com.microsoft.sqlserver.jdbc">
    <driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
</driver>
  • 注意点模块下包的结构和name对应起来

  • Spring使用JNDI数据源

<?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:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:jee="http://www.springframework.org/schema/jee"
       xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd


http://www.springframework.org/schema/aop


http://www.springframework.org/schema/aop/spring-aop.xsd


http://www.springframework.org/schema/tx


http://www.springframework.org/schema/tx/spring-tx.xsd


http://www.springframework.org/schema/context


http://www.springframework.org/schema/context/spring-context.xsd

    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
    ">

   <jee:jndi-lookup id="myDataSource1" jndi-name="java:jboss/datasources/OracleDS" />
   <jee:jndi-lookup id="myDataSource2" jndi-name="java:jboss/datasources/MssqlDS" />
</beans>
  • 控制台查看数据源

http://127.0.0.1:9990

如果无法进入控制台,需要配置用户和组,执行jboss-eap-6.2\bin\add-user.bat,按照提示执行。

http://xhope.top/wp-content/uploads/2016/02/1.jpg