Tomcat中的Java JNDI:全局资源上的BeanCreationException / NamingException。寻找全局资源返回的同一个类

时间:2018-01-26 11:54:47

标签: java spring tomcat7 jndi c3p0

我不明白什么原因导致Bean创建异常代表返回相同的类。

该类为com.mchange.v2.c3p0.ComboPooledDataSource,错误显示预计返回 [ com.mchange.v2.c3p0.ComboPooledDataSource ]但返回 [ com.mchange.v2.c3p0.ComboPooledDataSource ]的实例

这是错误:

org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'dataSourceGCA' defined in class path resource [META-INF/xxxxx-security-app.xml]: 
Invocation of init method failed; nested exception is javax.naming.NamingException: 
The local resource link [dataSourceGCA2] that refers to global resource [jdbc/dataSourceGCA2Global] was expected to return an instance of [com.mchange.v2.c3p0.ComboPooledDataSource] but returned an instance of [com.mchange.v2.c3p0.ComboPooledDataSource]

我正在使用Java 7和Tomcat 7。

这是数据源的配置:

context.xml 中:

<ResourceLink name="jdbc/dataSourceGCA2"
  global="jdbc/dataSourceGCA2Global"
  auth="Container"
  type="com.mchange.v2.c3p0.ComboPooledDataSource" />

server.xml 中:

<Resource description="whatever"
  name="jdbc/dataSourceGCA2Global"
  auth="Container"
  factory="org.apache.naming.factory.BeanFactory"
  type="com.mchange.v2.c3p0.ComboPooledDataSource"
  user="xxxxxxxx"
  password="xxxxxxxx"
  initialPoolSize="1"
  minPoolSize="1"
  maxPoolSize="5"
  acquireIncrement="1"
  driverClass="oracle.jdbc.driver.OracleDriver"
  jdbcUrl="jdbc:oracle:thin:@tprodva2:1522/BD2"
  testConnectionOnCheckin="true"
  idleConnectionTestPeriod="300"
  maxIdleTimeExcessConnections="0"
  maxIdleTime="0" />

什么会导致这种行为?

感谢任何帮助。

1 个答案:

答案 0 :(得分:2)

(会发表评论,但声名太低)

这可能是由两个不同的类加载器加载的同一个类引起的。