JNDI for Oracle 11 在 TC Server 中不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4619177/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 22:21:22  来源:igfitidea点击:

JNDI for Oracle 11 doesn't work in TC Server

oraclespring

提问by ffM

I'm trying for a few days configure a JNDI for Oracle 11 in TC Server, but no success. The intresting thing is when I do exactly the same thing for the Oracle 9, it works fine. My first though was the oracle jar file, but I'm using the newst one. So here my configurations and the error. If someone can give me a hint I will appreciate vey much.

我尝试了几天在 TC Server 中为 Oracle 11 配置 JNDI,但没有成功。有趣的是,当我为 Oracle 9 做完全相同的事情时,它运行良好。我的第一个虽然是 oracle jar 文件,但我使用的是最新的。所以这里是我的配置和错误。如果有人能给我一个提示,我将不胜感激。

In my application I have: applicationContext.xml (I use Spring 3, Hiberante and JPA for access the DB) here is only the JNDI, if someone needs more info here please let me know.

在我的应用程序中,我有:applicationContext.xml(我使用 Spring 3、Hiberante 和 JPA 来访问数据库)这里只是 JNDI,如果有人需要更多信息,请告诉我。

<jee:jndi-lookup id="oracle11DataSource" jndi-name="java:comp/env/jdbc/oracle11DataSource"`/>

web.xml

网页.xml

   <resource-ref>
     <res-ref-name>jdbc/oracle11DataSource</res-ref-name>
     <res-type>javax.sql.DataSource</res-type>
     <res-auth>Container</res-auth>
 </resource-ref> 

Server.xml:

服务器.xml:

<GlobalNamingResources>
    <Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>

    <Resource 
        driverClassName="oracle.jdbc.OracleDriver" 
        factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory" 
        maxActive="2" 
        maxIdle="1" 
        maxWait="5000" 
        name="jdbc/oracle11DataSource" 
        password="pwd" 
        type="javax.sql.DataSource" 
        url="jdbc:oracle:thin:@hostName:1521:SID" 
        username="username" 
        validationQuery="select 1"/> 

  </GlobalNamingResources>

I added the ojdbc6.jar in the lib folder of the server. When I start The TC Server here the Stack trace:

我在服务器的lib文件夹中添加了ojdbc6.jar。当我在这里启动 TC 服务器时,堆栈跟踪:

7/01/2011 8:39:28 AM org.apache.naming.NamingContext lookup
WARNING: Unexpected exception resolving reference
java.sql.SQLException
 at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:208)
 at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:157)
 at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:617)
 at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:561)
 at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:427)
 at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:132)
 at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:94)
 at org.apache.tomcat.jdbc.pool.DataSourceFactory.createDataSource(DataSourceFactory.java:477)
 at org.apache.tomcat.jdbc.pool.DataSourceFactory.getObjectInstance(DataSourceFactory.java:216)
 at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:140)
 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:153)
 at org.apache.catalina.core.NamingContextListener.addResource(NamingContextListener.java:1020)
 at org.apache.catalina.core.NamingContextListener.createNamingContext(NamingContextListener.java:629)
 at org.apache.catalina.core.NamingContextListener.lifecycleEvent(NamingContextListener.java:237)
 at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
 at org.apache.catalina.core.StandardContext.start(StandardContext.java:4540)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
 at org.apache.catalina.core.StandardHost.start(StandardHost.java:807)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
 at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
 at org.apache.catalina.core.StandardService.start(StandardService.java:519)
 at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
 at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
 at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.NullPointerException
 at java.lang.Class.forName0(Native Method)
 at java.lang.Class.forName(Class.java:247)
 at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:202)
 ... 32 more
7/01/2011 8:39:28 AM org.apache.catalina.core.NamingContextListener addResource
WARNING: Failed to register in JMX: javax.naming.NamingException
7/01/2011 8:39:28 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
7/01/2011 8:39:29 AM org.apache.tomcat.jdbc.pool.ConnectionPool init
WARNING: maxIdle is larger than maxActive, setting maxIdle to: 100
7/01/2011 8:39:29 AM org.apache.naming.NamingContext lookup
WARNING: Unexpected exception resolving reference
java.sql.SQLException
 at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:208)
 at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:157)
 at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:617)
 at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:561)
 at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:427)
 at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:132)
 at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:94)
 at org.apache.tomcat.jdbc.pool.DataSourceFactory.createDataSource(DataSourceFactory.java:477)
 at org.apache.tomcat.jdbc.pool.DataSourceFactory.getObjectInstance(DataSourceFactory.java:216)
 at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:140)
 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)
 at javax.naming.InitialContext.lookup(InitialContext.java:392)
 at org.springframework.jndi.JndiTemplate.doInContext(JndiTemplate.java:154)
 at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)
 at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
 at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)
 at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)
 at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)
 at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:201)
 at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:187)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getObject(AbstractBeanFactory.java:291)
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563)
 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
 at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
 at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
 at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
 at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4135)
 at org.apache.catalina.core.StandardContext.start(StandardContext.java:4630)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
 at org.apache.catalina.core.StandardHost.start(StandardHost.java:807)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
 at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
 at org.apache.catalina.core.StandardService.start(StandardService.java:519)
 at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
 at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
 at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.NullPointerException
 at java.lang.Class.forName0(Native Method)
 at java.lang.Class.forName(Class.java:247)
 at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:202)
 ... 57 more
2011-01-07 08:39:29,062 [main] ERROR org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'oracle11DataSource': Invocation of init method failed; nested exception is javax.naming.NamingException
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getObject(AbstractBeanFactory.java:291)
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563)
 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
 at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
 at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
 at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
 at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4135)
 at org.apache.catalina.core.StandardContext.start(StandardContext.java:4630)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
 at org.apache.catalina.core.StandardHost.start(StandardHost.java:807)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
 at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
 at org.apache.catalina.core.StandardService.start(StandardService.java:519)
 at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
 at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
 at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: javax.naming.NamingException
 at org.apache.naming.NamingContext.lookup(NamingContext.java:805)
 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)
 at javax.naming.InitialContext.lookup(InitialContext.java:392)
 at org.springframework.jndi.JndiTemplate.doInContext(JndiTemplate.java:154)
 at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)
 at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
 at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)
 at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)
 at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)
 at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:201)
 at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:187)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
 ... 27 more

I agree. I'm also used to put the tag in the context.xml. I put into server.xml because in the TC Server documentation the example say to put in the server.xml: http://static.springsource.com/projects/tc-server/6.0/admin/cadmresourcelink.html

我同意。我也习惯将标签放在 context.xml 中。我放入 server.xml 因为在 TC Server 文档中示例说放入 server.xml:http: //static.springsource.com/projects/tc-server/6.0/admin/cadmresourcelink.html

If I put the resouce in the context.xml here the error:

如果我将资源放在 context.xml 中,则会出现以下错误:

2011-01-07 13:24:20,234 [main] ERROR org.hibernate.util.JDBCExceptionReporter - Cannot create PoolableConnectionFactory (Listener refused the connection with the following error:
    ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
     )
    2011-01-07 13:24:20,234 [main] ERROR org.springframework.web.context.ContextLoader - Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lastUpdatedController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.controller.configuration.ApplicationData com.controller.component.LastUpdatedController.applicationData; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.controller.configuration.ApplicationData#0' defined in URL [file:/C:/tools/springsource-2.5-ga/tc-server-developer-2.0.4.RELEASE/tomcat-6.0.29.A.RELEASE/wtpwebapps/webapp/WEB-INF/classes/META-INF/spring/user.interface.xml]: Invocation of init method failed; nested exception is org.springframework.orm.jpa.JpaSystemException: org.hibernate.exception.GenericJDBCException: Cannot open connection; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Cannot open connection
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getObject(AbstractBeanFactory.java:291)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
        at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4135)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4630)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
        at org.apache.catalina.core.StandardHost.start(StandardHost.java:807)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
        at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
        at org.apache.catalina.core.StandardService.start(StandardService.java:519)
        at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
        at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
    Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.controller.configuration.ApplicationData com.controller.component.LastUpdatedController.applicationData; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.controller.configuration.ApplicationData#0' defined in URL [file:/C:/tools/springsource-2.5-ga/tc-server-developer-2.0.4.RELEASE/tomcat-6.0.29.A.RELEASE/wtpwebapps/webapp/WEB-INF/classes/META-INF/spring/user.interface.xml]: Invocation of init method failed; nested exception is org.springframework.orm.jpa.JpaSystemException: org.hibernate.exception.GenericJDBCException: Cannot open connection; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Cannot open connection
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:502)
        at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:282)
        ... 28 more
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.controller.configuration.ApplicationData#0' defined in URL [file:/C:/tools/springsource-2.5-ga/tc-server-developer-2.0.4.RELEASE/tomcat-6.0.29.A.RELEASE/wtpwebapps/webapp/WEB-INF/classes/META-INF/spring/user.interface.xml]: Invocation of init method failed; nested exception is org.springframework.orm.jpa.JpaSystemException: org.hibernate.exception.GenericJDBCException: Cannot open connection; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Cannot open connection
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getObject(AbstractBeanFactory.java:291)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:844)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:786)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703)
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:474)
        ... 30 more
    Caused by: org.springframework.orm.jpa.JpaSystemException: org.hibernate.exception.GenericJDBCException: Cannot open connection; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Cannot open connection
        at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:311)
        at org.springframework.orm.jpa.aspectj.JpaExceptionTranslatorAspect.ajc$afterThrowing$org_springframework_orm_jpa_aspectj_JpaExceptionTranslatorAspecta1ac9(JpaExceptionTranslatorAspect.aj:15)
        at com..domain.configuration.PropertyGroup_Roo_Entity.findAllPropertyGroups_aroundBody4(PropertyGroup_Roo_Entity.aj:91)
        at com..domain.configuration.PropertyGroup_Roo_Entity.ajc$interMethod$com._configuration_PropertyGroup_Roo_Entity$com_domain_configuration_PropertyGroup$findAllPropertyGroups(PropertyGroup_Roo_Entity.aj:1)
        at com..domain.configuration.PropertyGroup.findAllPropertyGroups(PropertyGroup.java:1)
        at com..controller.configuration.ApplicationData.load(ApplicationData.java:18)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1544)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1485)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
        ... 40 more
    Caused by: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Cannot open connection
        at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1235)
        at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1168)
        at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:250)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:310)
        at $Proxy45.getResultList(Unknown Source)
        ... 51 more
    Caused by: org.hibernate.exception.GenericJDBCException: Cannot open connection
        at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)
        at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)
        at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449)
        at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
        at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:161)
        at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1616)
        at org.hibernate.loader.Loader.doQuery(Loader.java:717)
        at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270)
        at org.hibernate.loader.Loader.doList(Loader.java:2449)
        at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2192)
        at org.hibernate.loader.Loader.list(Loader.java:2187)
        at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:452)
        at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
        at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
        at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1258)
        at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
        at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:241)
        ... 57 more
    Caused by: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Listener refused the connection with the following error:
    ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
     )
        at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
        at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
        at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
        at org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:71)
        at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
        ... 71 more

采纳答案by a_horse_with_no_name

I'm not sure if the pool will run the validation query during initialization.

我不确定池是否会在初始化期间运行验证查询。

But if that happens then your validation query might be the problem because select 1is not a valid Oracle statement. You need to use select 1 from dual

但如果发生这种情况,那么您的验证查询可能是问题所在,因为select 1它不是有效的 Oracle 语句。你需要使用select 1 from dual

But then I would expect to see a different error message.

但随后我希望看到不同的错误消息。

Edit
Another thing:

编辑
另一件事:

Are you sure your <GlobalNamingResource> tag is correct?

你确定你的 <GlobalNamingResource> 标签是正确的吗?

All JNDI DataSources that I have used so far where put into the web application's context.xml into a <Resource>tag.

到目前为止,我使用的所有 JNDI 数据源都将 Web 应用程序的 context.xml 放入<Resource>标记中。

<Context>
  <Resource name="jdbc/oracle11DataSource" 
            type="javax.sql.DataSource"
            ..../>
</Context>

Basically the way it is described in the Tomcat manual:
http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html#JDBC_Data_Sources

基本上是Tomcat手册中描述的方式:http:
//tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html#JDBC_Data_Sources

Edit 2
The error message TNS:listener does not currently know of SID given in connect descriptorclearly shows that the value for SIDin the JDBC URL is incorrect.

编辑 2
错误消息TNS:listener 不知道连接描述符中给出的 SID清楚地表明SIDJDBC URL 中的值不正确。

回答by lochgorman

I had the same problem in one of my projects for the error message "TNS:listener does not currently know of SID given in connect descriptor "c i could connect through sql developer with the sid but not through the webserver and fixed the problem by changing

我在我的一个项目中遇到了同样的问题,因为错误消息“TNS:listener 目前不知道连接描述符中给出的 SID”c 我可以通过 sql developer 与 sid 进行连接,但不能通过网络服务器连接,并通过更改解决了问题

url="jdbc:oracle:thin:@hostname:1521:sid"

url="jdbc:oracle:thin:@hostname:1521:sid"

to

url="jdbc:oracle:thin:@hostname:1521/sid"

url="jdbc:oracle:thin:@hostname:1521/sid"