从Jboss 6.3服务器

时间:2015-05-15 18:09:57

标签: java jboss datasource jboss6.x

  

22:25:32,256错误   [org.apache.catalina.core.ContainerBase [jboss.web] [缺省主机]。[/ TestDatasource]。[JSP]]   (http- / 127.0.0.1:8080-2)JBWEB000236:servlet的Servlet.service()   jsp抛出异常:javax.naming.NameNotFoundException:comp / env -   服务jboss.naming.context.java.comp.env at   org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:103)     在org.jboss.as.naming.NamingContext.lookup(NamingContext.java:197)     在   org.jboss.as.naming.InitialContext $ DefaultInitialContext.lookup(InitialContext.java:241)     在org.jboss.as.naming.NamingContext.lookup(NamingContext.java:183)     在org.jboss.as.naming.NamingContext.lookup(NamingContext.java:179)     在javax.naming.InitialContext.lookup(未知来源)   [rt.jar:1.8.0_25]在javax.naming.InitialContext.lookup(未知   来源)[rt.jar:1.8.0_25] at   com.java.DBConnection.getConnection(DBConnection.java:27)[classes:]     在org.apache.jsp.index_jsp._jspService(index_jsp.java:66)

的web.xml

<resource-ref>
    <description>Oracle Datasource example</description>
    <res-ref-name>java:jboss/datasources/<datasource name></res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

standalone.xml

<datasource jta="false" jndi-name="java:jboss/datasources/<datasource name>"     pool-name="<pool name>" enabled="true" use-ccm="false">
    <connection-url>jdbc:oracle:thin:@<IP>:<port>:DB</connection-url>
    <driver-class>oracle.jdbc.OracleDriver</driver-class>
    <driver>oracleDS</driver>
    <security>
        <user-name><user></user-name>
        <password>pass</password>
    </security>
</datasource>

<driver name="oracleDS" module="com.oracle.ojdbc6">
    <xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
</driver>

Module.xml

<module xmlns="urn:jboss:module:1.0" name="com.oracle.ojdbc6">
    <resources>
        <resource-root path="ojdbc6.jar"/>
    </resources>
    <dependencies>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>
    </dependencies>
</module>

DBConnection.java

Context initContext = new InitialContext();
Context envContext  = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/TAXLOT_JNDI_DATASOURCE");
Connection connection = ds.getConnection();

0 个答案:

没有答案