JBoss - 无法取消引用对象

时间:2013-04-24 13:22:33

标签: gwt jboss datasource jndi connection-pooling

我用jetty创建了GWT项目,我使用JNDI作为数据源。当我运行GWT应用程序时一切正常,但是当我将.war文件复制到JBoss并运行它时,会出错。 JBoss版本 - 4.2.3.GA

javax.naming.NamingException: Could not dereference object [Root exception is 
javax.naming.NameNotFoundException: jdbc not bound] at 
org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1215) at 
org.jnp.interfaces.NamingContext.lookup(NamingContext.java:758) at 
org.jnp.interfaces.NamingContext.lookup(NamingContext.java:774) at 
org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627) at 
javax.naming.InitialContext.lookup(InitialContext.java:392) at 

的JBoss-web.xml中

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
    <resource-ref>
        <res-ref-name>jdbc/base</res-ref-name>
        <jndi-name>jdbc/base</jndi-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>
</jboss-web>

码头-env.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
<Configure class="org.mortbay.jetty.webapp.WebAppContext">
<New id="base" class="org.mortbay.jetty.plus.naming.Resource">
    <Arg>jdbc/base</Arg>
    <Arg>
     <New class="org.apache.tomcat.jdbc.pool.DataSource">
            <Set name="driverClassName">org.postgresql.Driver</Set>
            <Set name="url">jdbc:postgresql://database/test</Set>
            <Set name="username">user</Set>
            <Set name="password">password</Set>
            <Set name="maxActive">10</Set>
            <Set name="maxIdle">4</Set>
     </New>
    </Arg>
</New>
</Configure>

的web.xml

<resource-ref>
    <description>My DataSource Reference</description>
    <res-ref-name>jdbc/base</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

GreetingServiceImpl.java

        InitialContext ic = new InitialContext();
        DataSource ds = (DataSource)ic.lookup("java:comp/env/jdbc/base");
        Connection con = ds.getConnection();

怎么了?谢谢你的帮助

1 个答案:

答案 0 :(得分:1)

我已经解决了我的问题。我创建了base-ds.xml

<datasources>
   <local-tx-datasource>
      <jndi-name>jdbc/base</jndi-name>
      <connection-url>jdbc:postgresql://database/test</connection-url>
      <driver-class>org.postgresql.Driver</driver-class>
      <user-name>user</user-name>
      <password>password</password>
      <min-pool-size>4</min-pool-size>
      <max-pool-size>10</max-pool-size>
   </local-tx-datasource>
</datasources>

我在jboss-web.xml中更改了jndi-name

    <jndi-name>java:/jdbc/base</jndi-name>

如何在JBoss中为此数据源连接Tomcat连接池?