在尝试查找JNDI上下文时,我遇到了以下异常,尽管此站点上已经回答了类似的问题,将类路径中缺少的tibjms.jar
称为根本原因。
java.lang.ClassCastException: com.tibco.tibjms.naming.TibjmsFederatedQueueConnectionFactory cannot be cast to javax.jms.QueueConnectionFactory
at com.xxx.host.tibco.ConnectionHandler$JMSConnectionFactory.<init>(ConnectionHandler.java:337)
at com.xxx.host.tibco.ConnectionHandler.init(ConnectionHandler.java:94)
at com.xxx.host.tibco.ConnectionHandler.<init>(ConnectionHandler.java:84)
at com.xxx.host.tibco.ConnectionHandler.getInstance(ConnectionHandler.java:63)
at com.xxx.productOne.host.HostGetMemberBalanceRequest.doDecision(HostGetMemberBalanceRequest.java:42)
at com.audium.server.voiceElement.DecisionElementBase.service(DecisionElementBase.java:386)
at com.audium.server.controller.Controller.goToDecision(Controller.java:2857)
at com.audium.server.controller.Controller.goToElement(Controller.java:2687)
at com.audium.server.controller.Controller.continueCall(Controller.java:2511)
at com.audium.server.controller.Controller.goToElement(Controller.java:2742)
at com.audium.server.controller.Controller.continueCall(Controller.java:2511)
at com.audium.server.controller.Controller.doPost(Controller.java:733)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:879)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Thread.java:662)
除此之外,我在同一服务器上使用相同的代码段,而该服务器版本/编号完全相同。 TOMCAT中的库。
以下是如何查找上下文的代码片段:
InitialContext iniCtx;
try {
iniCtx = new InitialContext(oProperties);
PoolableObjectFactory objectFactory = new JMSConnectionFactory(iniCtx);
this.pool = new GenericObjectPool(objectFactory);
createQueues(iniCtx);
singleton = this;
System.out.println("Connection Handler is initialized");
} catch (NamingException ne) {
ne.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
非常感谢您提供任何故障排除帮助。
最佳答案
这样的问题始终是由不同的类加载器加载的一个类(在这种情况下为javax.jms.QueueConnectionFactory)。通常但并非总是如此,不同的类加载器意味着与类加载位置不同的位置。依次从中加载类的位置很容易在调试器中找到
javax.jms.QueueConnectionFactory.class.getProtectionDomain().getCodeSource().getLocation();
和
connectionFactory.getSuperclass()..
如果位置在大多数情况下不同,则原因会立即得到澄清。