我在Eclipse Neon中运行TomEE 7.0.1。我在" tomee.xml"中定义了一个DataSource资源。文件。 DataSource连接到Oracle DB,我从我当地的Maven仓库获取驱动程序。
当TomEE启动时,我在控制台中收到以下错误:
org.apache.tomcat.jdbc.pool.PoolExhaustedException: [main] NoWait: Pool empty. Unable to fetch a connection, none available[5 in use].
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:679)
at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:468)
at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:143)
at org.apache.tomee.jdbc.TomEEDataSourceCreator$TomEEConnectionPool.<init>(TomEEDataSourceCreator.java:221)
这是我的资源定义:
<Resource id="global/foo/bar" type="DataSource" classpath="mvn:oracle:ojdbc6:11.2.0.3">
JdbcDriver = oracle.jdbc.driver.OracleDriver
MaxActive = 5
MinIdle = 2
MaxIdle = 2
MaxWait = 10000
JdbcUrl = jdbc:oracle:thin:@<host>:1521:sus2
UserName = <userid>
Password = <password>
</Resource>
我已经删除了主机,用户和密码,但ID是写的。我仍然不确定JNDI查找,但这显然是一个单独的问题。
这是我在Spring上下文中的JNDI查找引用:
<jee:jndi-lookup jndi-name="java:global/foo/bar" id="sus2ds"/>
这里有更多Tomcat控制台输出:
INFO: Configuring Service(id=global/foo/bar, type=Resource, provider-id=Default JDBC Database)
...
INFO: Creating Resource(id=global/foo/bar)
Aug 03, 2016 11:08:27 AM org.apache.tomcat.jdbc.pool.ConnectionPool checkPoolConfiguration
WARNING: initialSize is larger than maxActive, setting initialSize to: 5
Aug 03, 2016 11:08:27 AM org.apache.tomcat.jdbc.pool.ConnectionPool init
SEVERE: Unable to create initial connections of pool.
org.apache.tomcat.jdbc.pool.PoolExhaustedException: [main] NoWait: Pool empty. Unable to fetch a connection, none available[5 in use].
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:679)
at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:468)
at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:143)
at org.apache.tomee.jdbc.TomEEDataSourceCreator$TomEEConnectionPool.<init>(TomEEDataSourceCreator.java:221)
...
Aug 03, 2016 11:08:27 AM org.apache.tomee.jdbc.TomEEDataSourceCreator$TomEEDataSource <init>
SEVERE: Can't create DataSource
org.apache.tomcat.jdbc.pool.PoolExhaustedException: [main] NoWait: Pool empty. Unable to fetch a connection, none available[5 in use].
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:679)
at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:468)
at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:143)
at org.apache.tomee.jdbc.TomEEDataSourceCreator$TomEEConnectionPool.<init>(TomEEDataSourceCreator.java:221)
...
...
2016-08-03 11:08:30,080 WARN [localhost-startStop-1] support.AbstractApplicationContext (AbstractApplicationContext.java:549) - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sus2ds': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name "foo/bar" not found.
2016-08-03 11:08:30,084 ERROR [localhost-startStop-1] context.ContextLoader (ContextLoader.java:351) - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sus2ds': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name "foo/bar" not found.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
...
Caused by: javax.naming.NameNotFoundException: Name "foo/bar" not found.
at org.apache.openejb.core.ivm.naming.IvmContext.federate(IvmContext.java:199)
at org.apache.openejb.core.ivm.naming.IvmContext.lookup(IvmContext.java:151)
at org.apache.openejb.core.ivm.naming.IvmContext.lookup(IvmContext.java:291)
at org.apache.naming.NamingContext.lookup(NamingContext.java:828)
...
Aug 03, 2016 11:08:30 AM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sus2ds': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name "foo/bar" not found.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
...
Caused by: javax.naming.NameNotFoundException: Name "foo/bar" not found.
at org.apache.openejb.core.ivm.naming.IvmContext.federate(IvmContext.java:199)
at org.apache.openejb.core.ivm.naming.IvmContext.lookup(IvmContext.java:151)
at org.apache.openejb.core.ivm.naming.IvmContext.lookup(IvmContext.java:291)
at org.apache.naming.NamingContext.lookup(NamingContext.java:828)
...
答案 0 :(得分:0)
我将启动服务器并使用MBean资源管理器或JNDI资源管理器webapp来查看JNDI树并获取正确的名称。我怀疑你不需要id="global/foo/bar"
而是id="foo/bar"
并且在Spring代码中保持查找相同。