当前位置: 代码迷 >> JBoss >> struts的web项目发布到Jboss服务器下出现java.lang.ClassCastException
  详细解决方案

struts的web项目发布到Jboss服务器下出现java.lang.ClassCastException

热度:5214   发布时间:2013-02-26 00:00:00.0
struts的web项目发布到Jboss服务器上出现java.lang.ClassCastException
今天做一个struts的web小项目发布到JBoss 4.0上出现了
java.lang.ClassCastException: com.sun.faces.config.WebConfiguration cannot be cast to com.sun.faces.config.WebConfiguration 
at com.sun.faces.config.WebConfiguration.getInstance(WebConfiguration.java:154) 
.... 
.... 
.... 
.... 
.... 
.... 
我就上网查啊 查到几个说是包的问题
由jsf版本引起的,删除lib下的两个JSF相关的包jsf-impl.jar和jsf-api.jar
开始我删除了又出现ClassNotFundExceptions
我继续goole看到一个英文的论坛上又关这个错误的解决方法就是把jboss目录下
的\server\default\deploy\jboss-web.deployer\conf里的web.xml里的
<listener>
     <listener-class>org.jboss.web.jsf.integration.config.JBossJSFConfigureListener</listener-class>
</listener>

<listener>
     <listener-class>com.sun.faces.application.WebappLifecycleListener</listener-class>
 </listener>
删除或者注释掉,试了下果然行,但是我不知道原因,而且这样改了会不会影响其他项目。
小鸟英文水平有限,看不明白他的解释,他的原文是这样的
----- 
This is the original post 
---- 


Error running JSF with Jboss 
Error: The specified InjectionProvider implementation 'org.jboss.web.jsf.integration.injection.JBossDelegatingInjectionProvider' does not implement the InjectionProvider interface. 

Solution: 
You need to remove the bundled JSF implementation. To do so you need to comment/remove the following from the web.xml found under jboss-4.2.0.GA\server\\deploy\jboss-web.deployer\conf. 

Under jboss 5.0.0GA jboss-5.0.0.GA\server\default\deployers\jbossweb.deployer\web.xml 

<!-- Comment/Remove this --> 
<!-- Configures JSF for a web application if the javax.faces.webapp.FacesServlet is declared --> 
<!-- in web.xml. --> 
<!-- 
<listener> 
<listener-class>org.jboss.web.jsf.integration.config.JBossJSFConfigureListener </listener-class> 
</listener> 
--> 
<!-- Comment/Remove this --> 
<!-- Listens to all web app lifecycle events so that @PreDestroy can be called on --> 
<!-- JSF managed beans that go out of scope. You can comment this out if you --> 
<!-- don't use JSF or you don't use annotations on your managed beans. --> 
<!-- 
<listener> 
<listener-class>com.sun.faces.application.WebappLifecycleListener</listener-class> 
</listener> 
--> 
哪位大牛能说说这是为什么,或者又其他的解决办法
------解决方案--------------------------------------------------------
通常我们区别两个类是根据包名,比如 com.hp.Person和Com.hp1.Person 尽管类名相同,但是包名不同,所以是不同的类。
事实上,我们还需要根绝jarfile是否相同来区分的。
但是如果遇到两个不同的package,但是它们都有一个类: com.hp.Person
事实上这两个类是不同的。
估计lz遇到的就是这个问题。
  相关解决方案