错误描述:
今天用jsp调用一个会话bean的时候,出现了一个“java.lang.ClassCastException: $Proxy65”的错误,百度了一下,中文的解释是:
说JBOSS的WEB加载器默认是FALSE,根据配置文件的说明,其目的就是当出现多个加载器的时候,通过设定真假值来决定是否把JBOSS的WEB加载器作为统一的加载器。也就是说,如果在程序中特殊指明了某一个加载器,或者lib中用到了其它版本tomcat的JAR包,那么JBOSS自带的加载器设为FLASE,就会导致WAR包的JAR和类文件都没有被JBOSS的加载器加载。
解决办法:
把JBOSS自带的加载器由默认的FALSE改为TRUE。
解决细节:
修改jboss-4.2.3.GA/server/default/deploy/jboss-web.deployer/META-INF下的jboss-service.xml文件中的
seJBossWebLoader属性改为true(默认是false)。
改后:
<attribute name="UseJBossWebLoader">true</attribute>
下面是一段英文的解释:
See ClassLoadingConfiguration.
Available option in deploy/jbossweb-tomcat.sar/META-INF/jboss-service.xml
or deploy/jboss-web.deployer/META-INF/jboss-service.xml
This configuration options toggles usage of separate classloaders for web modules. The JBoss unified classloader holds all the classes from multiple web applications in one big classloader and may cause unwanted interference.
Example
Imagine web modules "sales.war" and "stock.war", both containing some version of "utility.jar". In case "sales.war" uses version 1.0 and "stock.war" requires version 2.0, turning off the unified web loader is the safest solution. If you don't, the first loaded library will have priority, and remains in the classloader till the reference count drops to zero.
The disadvantage of using isolated classloaders: either you need to duplicate the same library across multiple web modules, or add it to the classpath of your server instance (default: lib/). The instance libraries are defaults, they can be overridden when the web module contains it's own custom versions.
The configuration file contains a small comment about isolation of JSP files as well, to separate two JSP files with the same name from two different web modules. In JBoss 4.0.5, using non-precompiled JSP pages, this seems to work fine, even with the JBoss unified web loader.