錯誤描述:
今天用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.