javax.naming.NamingException: Cannot create resource instance
at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:143)
at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
at org.apache.naming.NamingContext.lookup(NamingContext.java:793)
at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:152)我用的是Tomcat6.0,struts2.2.3、jdk1.6
context.xml:
<?xml version='1.0' encoding='utf-8'?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.  See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License.  You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- The contents of this file will be loaded for each web application -->
<Context> <!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource> <!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
--> <!-- Uncomment this to enable Comet connection tacking (provides events
on session expiration as well as webapp lifecycle) -->
<!--
<Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
--> <Resource name="jdbc/test" auth="Container"
type="org.apache.commons.dbcp.BasicDataSource" driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@192.168.0.66:1521:ORADB" username="ACOS2_ORDER" password="ACOS2_ORDER"
maxActive="10" 
maxIdle="0"
maxWait="-1" />
</Context>请问是什么啊?在线等.很急!!!
我已经把commons-dbcp-1.2.2.jar拷贝到了.TOMCATE的LIB下.

解决方案 »

  1.   

    context.xml中加入以下配置项
    <Context>
    <ResourceLink global="jdbc/NEWDB" name="jdbc/NEWDB" type="javax.sql.DataSource"/> 
    </Context>
    然后在server.xml中加入以下配置项
    <GlobalNamingResources><Resource name="jdbc/test" auth="Container"
    type="org.apache.commons.dbcp.BasicDataSource" driverClassName="oracle.jdbc.driver.OracleDriver"
    url="jdbc:oracle:thin:@192.168.0.66:1521:ORADB" username="ACOS2_ORDER" password="ACOS2_ORDER"
    maxActive="10"  
    maxIdle="0"
    maxWait="-1"/></GlobalNamingResources>
      

  2.   

    type="org.apache.commons.dbcp.BasicDataSource" 
    换成
    java.sql.DataSource试试?
      

  3.   

    按上面加完以后,报下面的错误:致命的: Exception processing Global JNDI Resources
    javax.naming.NamingException: Cannot create resource instance
    at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:143)
    at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:793)请问为什么呀?
      

  4.   

    这是我在用的一个c3p0的连接池配置<bean id="dataSourceSpring"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="${jdbc.DirverClass}" />
    <property name="url" value="${jdbc.Url}" />
    <property name="username" value="${jdbc.UserName}" />
    <property name="password" value="${jdbc.PassWord}" />
    </bean>

    <bean id="dataSourceC3p0" class="com.mchange.v2.c3p0.ComboPooledDataSource"
    destroy-method="close">
    <property name="driverClass" value="${jdbc.DirverClass}" />
    <property name="jdbcUrl" value="${jdbc.Url}" />
    <property name="user" value="${jdbc.UserName}" />
    <property name="password" value="${jdbc.PassWord}" />
    <!--连接池中保留的最小连接数。-->
    <property name="minPoolSize" value="${cpool.minPoolSize}" />
    <!--连接池中保留的最大连接数。Default: 15 -->
    <property name="maxPoolSize" value="${cpool.maxPoolSize}" />
    <!--初始化时获取的连接数,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->
    <property name="initialPoolSize" value="${cpool.initialPoolSize}" />
    <!--最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
    <property name="maxIdleTime" value="${cpool.maxIdleTime}" />
    <!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->
    <property name="acquireIncrement" value="${cpool.acquireIncrement}" />
    <!--
    JDBC的标准参数,用以控制数据源内加载的PreparedStatements数量。但由于预缓存的statements
    属于单个connection而不是整个连接池。所以设置这个参数需要考虑到多方面的因素。
    如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0
    -->
    <property name="maxStatements" value="${cpool.maxStatements}" />
    <property name="maxStatementsPerConnection" value="${cpool.maxStatementsPerConnection}" />
    <!--每60秒检查所有连接池中的空闲连接。Default: 0 -->
    <property name="idleConnectionTestPeriod" value="${cpool.idleConnectionTestPeriod}" />
    <!--定义在从数据库获取新连接失败后重复尝试的次数。Default: 30 -->
    <property name="acquireRetryAttempts" value="${cpool.acquireRetryAttempts}" />
    <!--
    获取连接失败将会引起所有等待连接池来获取连接的线程抛出异常。但是数据源仍有效
    保留,并在下次调用getConnection()的时候继续尝试获取连接。如果设为true,那么在尝试
    获取连接失败后该数据源将申明已断开并永久关闭。Default: false
    -->
    <property name="breakAfterAcquireFailure" value="${cpool.breakAfterAcquireFailure}" />
    <!--
    因性能消耗大请只在需要的时候使用它。如果设为true那么在每个connection提交的
    时候都将校验其有效性。建议使用idleConnectionTestPeriod或automaticTestTable
    等方法来提升连接测试的性能。Default: false
    -->
    <property name="testConnectionOnCheckout" value="${cpool.testConnectionOnCheckout}" />
    </bean>
      

  5.   

    JNDI 连接数据库错误,你配置的jdbc/test连接不到数据库,看看驱动 URL 什么的有没有写错....