简体   繁体   English

Oracle JDBC驱动程序冲突

[英]Oracle JDBC driver conflict

JBoss EAP 6.1 standlone server JBoss EAP 6.1 standlone服务器

Application deployed as a war file throws a runtime exception 部署为war文件的应用程序会引发运行时异常

java.lang.ClassCastException: oracle.sql.ARRAY cannot be cast to oracle.sql.ARRAY

at line 在线

oracle.sql.ARRAY obj = (oracle.sql.ARRAY) rs.getObject("RATINGOBJ");

JDBC libary included is ojdbc6.jar (WEB_INF/lib). 包含的JDBC库是ojdbc6.jar(WEB_INF / lib)。 All libraries are included in the war file and there are no "global" libaries setup on the server. 所有库都包含在war文件中,并且服务器上没有设置“全局”库。 I have verified no other jdbc libraries are included anywhere in the app. 我已经验证应用程序中的任何地方都没有包含其他jdbc库。

In order to create a JDBC datasource, i created a deployment for ojdbc6.jar. 为了创建JDBC数据源,我为ojdbc6.jar创建了一个部署。 This is the only possible source of conflict i can think of. 这是我能想到的唯一可能的冲突根源。 When i remove the ojdbc6.jar from the war file, i get a ClassNotFound exception in place of the ClassCastException. 当我从war文件中删除ojdbc6.jar时,我得到一个ClassNotFound异常来代替ClassCastException。

Every other part of the app works fine except this line. 应用程序的每个其他部分工作正常,除了这一行。 How do i debug this any further? 我如何进一步调试这个?

You should not have any JDBC driver JARs at the WEB-INF/lib level. 您不应该在WEB-INF / lib级别拥有任何JDBC驱动程序JAR。 Java EE app servers need them to be at the app server level. Java EE应用服务器需要它们处于应用服务器级别。

Move it into the default server /lib directory and see if that's better. 将其移动到默认的server / lib目录中,看看是否更好。

I am not sure why loading from web-inf/lib will not work. 我不确定为什么从web-inf / lib加载不起作用。 Most likely the classloader's are different. 最有可能的是类加载器是不同的。

Do the first two steps for diagnosis. 做前两步诊断。 After that try one of the two alternatives below to fix the problem. 之后尝试以下两种替代方案中的一种来解决问题。
1) Check if the class loaders are the same by comparing the rs.getObject().getClass('RATINGOBJ').getClassLoader() and oracle.sql.ARRAY.class.getClassLoader() If you do equals between the two classloaders, it should return false as it looks that the classloaders are different. 1)通过比较rs.getObject().getClass('RATINGOBJ').getClassLoader() )来检查类加载器是否相同rs.getObject().getClass('RATINGOBJ').getClassLoader()oracle.sql.ARRAY.class.getClassLoader()如果你在两个类加载器之间做equals它应该返回false,因为它看起来类加载器是不同的。 Check an explanation at ClassCastException when casting to the same class 在转换为同一个类时,检查ClassCastException的解释

This problem has already been reported earlier in another forum at https://forums.oracle.com/message/9330314 . 此问题已在之前的另一个论坛https://forums.oracle.com/message/9330314中报告过。 Moving jars around in jboss will still result in same problems. 在jboss中移动jar仍然会导致相同的问题。

2) Find out the source jars from where the classes are getting loaded and remove the jar that you dont need. 2)找出从哪里加载类的源jar并删除你不需要的jar。 Find the jars for the two different classes by checking 通过检查找到两个不同类的罐子
rs.getObject().getClass('RATINGOBJ').getProtectionDomain().getCodeSource().getLocation() oracle.sql.ARRAY.class.getProtectionDomain().getCodeSource().getLocation() - Determine which JAR file a class is from rs.getObject().getClass('RATINGOBJ').getProtectionDomain().getCodeSource().getLocation() oracle.sql.ARRAY.class.getProtectionDomain().getCodeSource().getLocation() - 确定哪个JAR文件是一个类来自

Possible Solutions: 可能的解决方案:

a) If you need both the jars, y'll have to move the Jar of rs.getObject().getClass('RATINGOBJ').getProtectionDomain().getCodeSource().getLocation() a)如果你需要两个罐子,你必须移动rs.getObject().getClass('RATINGOBJ').getProtectionDomain().getCodeSource().getLocation()的罐子rs.getObject().getClass('RATINGOBJ').getProtectionDomain().getCodeSource().getLocation()

and create the module as specified at http://www.javaworld.com/community/node/8184 . 并按照http://www.javaworld.com/community/node/8184中的规定创建模块。

b) If you still cant get classes to be loaded as you expect, Specify the library in jboss server library. b)如果仍然无法按预期加载类,请在jboss服务器库中指定库。

c) The last solution to force classes to be loaded from a particular jar is by specifying the jar in the bootclasspath. c)强制从特定jar加载类的最后一个解决方案是在bootclasspath中指定jar。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM