TNS:no appropriate service handler found
和
ORA-01017: invalid username/password; logon denied
但是,如果JNDI中只有一个数据源,意味着另一个使用常规JDBC数据源,则应用程序就像魅力一样运行
两个数据源都来自相同的db URL,但使用不同的模式.
我的猜测是,它可能是由具有不同用户名/密码(架构)的每个资源的相同数据库URL引起的.但是tomcat应该能够处理这种情况,所以我的理由是可能有一些我错过的配置?
另一个有趣的发现是:
当我使用jdbc url jdbc:oracle:thin:@myhost:1521:orcl与sql Developer建立连接时,有时它连接没有问题,但有时会被同一问题拒绝:在此Web应用程序中找到适当的服务处理程序同时活跃.但是,相同的JDBC URL与另一个具有常规JDBC连接(而不是JNDI)的Spring应用程序一起工作正常.那诀窍是什么?
以下是当前配置的详细信息:
在Context.xml中
<Resource name="jdbc/app_A" auth="Container" type="javax.sql.DataSource" driverClassName="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@myhost:1521:orcl" username="usernameA" password="passwordA" maxActive="20" maxIdle="10" maxWait="-1" /> <Resource name="jdbc/app_B" auth="Container" type="javax.sql.DataSource" driverClassName="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@myhost:1521:orcl" username="usernameB" password="usernameB" maxActive="20" maxIdle="10" maxWait="-1" />
在应用程序的Web.xml中:
<resource-ref> <description>Oracle Datasource for app_A</description> <res-ref-name>jdbc/app_A</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> <resource-ref> <description>Oracle Datasource for app_B</description> <res-ref-name>jdbc/app_B</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
在ApplicationContext.xml中
<jee:jndi-lookup id="dataSource1" jndi-name="java:comp/env/jdbc/app_A" resource-ref="true" /> <jee:jndi-lookup id="dataSource2" jndi-name="java:comp/env/jdbc/app_B" resource-ref="true" />
最后我得到了这样的例外情况:
Jan 31,2013 3:36:55 PM org.apache.catalina.core.NamingContextListener addResource WARNING: Failed to register in JMX: javax.naming.NamingException: ORA-01017: invalid username/password; logon denied Jan 31,2013 3:36:56 PM org.apache.naming.NamingContext lookup WARNING: Unexpected exception resolving reference java.sql.sqlException: Listener refused the connection with the following error: ORA-12519,TNS:no appropriate service handler found at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:412) at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:531) at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:221) at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32) at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:503) at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:278) at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:182) at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:699) at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:631) at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:485) at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:143) at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:116) at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:103) at org.apache.tomcat.jdbc.pool.DataSourceFactory.createDataSource(DataSourceFactory.java:539) at org.apache.tomcat.jdbc.pool.DataSourceFactory.getObjectInstance(DataSourceFactory.java:237) 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:843) at org.apache.naming.NamingContext.lookup(NamingContext.java:154) at org.apache.naming.NamingContext.lookup(NamingContext.java:831) at org.apache.naming.NamingContext.lookup(NamingContext.java:168) at org.apache.catalina.core.NamingContextListener.addResource(NamingContextListener.java:1061) at org.apache.catalina.core.NamingContextListener.createNamingContext(NamingContextListener.java:671) at org.apache.catalina.core.NamingContextListener.lifecycleEvent(NamingContextListener.java:270) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119) at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5173) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:618) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1100) at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1618) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662) Caused by: oracle.net.ns.NetException: Listener refused the connection with the following error: ORA-12519,TNS:no appropriate service handler found at oracle.net.ns.NSProtocol.connect(NSProtocol.java:385) at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1042) at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:301) ... 38 more Jan 31,2013 3:36:56 PM org.apache.catalina.core.NamingContextListener addResource WARNING: Failed to register in JMX: javax.naming.NamingException: Listener refused the connection with the following error: ORA-12519,TNS:no appropriate service handler found Jan 31,TNS:no appropriate service handler found
真的不确定为什么没有合适的服务处理程序发现错误弹出,似乎orcl Listener不接受/理解连接.
这是我插入persisntence.xml的内容
<persistence-unit name="persistenceUnit1"> .... <jta-data-source>jdbc/app_A</jta-data-source> .... </persistence-unit> <persistence-unit name="persistenceUnit2"> .... <jta-data-source>jdbc/app_B</jta-data-source> .... </persistence-unit>
jdbc:oracle:thin:@//host_name:port_number/service_name
还有一条说明“启动Oracle数据库10g,不支持Oracle服务ID”.因此,您使用的语法必须适用于Oracle 9i.它可能适用于较新的版本,但不能保证.
因此,请考虑更改JDBC连接字符串的格式,以遵循指南中建议的格式.
此外,对于Oracle 9i以上,您应该使用oracle.jdbc.OracleDriver而不是oracle.jdbc.driver.OracleDriver,因为Oracle已经声明不推荐使用oracle.jdbc.driver.OracleDriver,并且将停止对此驱动程序类的支持.