JBoss 7: ClassCastException: MyCustomTag 无法转换为 javax.servlet.jsp.tagext.Tag
JBoss 7: ClassCastException: MyCustomTag cannot be cast to javax.servlet.jsp.tagext.Tag
在 JBoss 服务器中部署包含自定义标记的 Web 应用程序出现以下异常:
java.lang.ClassCastException: com.test.taglib.MyCustomTag cannot be cast to javax.servlet.jsp.tagext.Tag
at org.apache.jasper.runtime.PerThreadTagHandlerPool.get(PerThreadTagHandlerPool.java:96) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.jsp.WEB_002dINF.jsp.testAppData_jsp._jspx_meth_fx_005fsystemDate_005f0(testAppData_jsp.java:725)
at org.apache.jsp.WEB_002dINF.jsp.testAppData_jsp._jspService(testAppData_jsp.java:150)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:69) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:365) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:309) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:242) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:832) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:620) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:553) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:482) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238) [org.springframework.web.servlet-3.0.7.RELEASE.jar:3.0.7.RELEASE]
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250) [org.springframework.web.servlet-3.0.7.RELEASE.jar:3.0.7.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1047) [org.springframework.web.servlet-3.0.7.RELEASE.jar:3.0.7.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817) [org.springframework.web.servlet-3.0.7.RELEASE.jar:3.0.7.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719) [org.springframework.web.servlet-3.0.7.RELEASE.jar:3.0.7.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:669) [org.springframework.web.servlet-3.0.7.RELEASE.jar:3.0.7.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:574) [org.springframework.web.servlet-3.0.7.RELEASE.jar:3.0.7.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
我的自定义标签 class
public class MyCustomTag extends BodyTagSupport {
...
}
MyCustomTag 间接继承 Tag class:MyCustomTag -> BodyTagSupport -> BodyTag -> IterationTag -> Tag
所有标签classes被打包成jsp-api-2.1.jar并包含在module.xml中,如下图:
module.xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com">
<resources>
...
<resource-root path="jsp-api-2.1.jar"/>
...
</resources>
<dependencies>
<module name="sun.jdk"/>
<module name="javax.api"/>
<module name="javax.servlet.api"/>
<module name="org.jboss.logging"/>
<module name="org.jboss.modules"/>
</dependencies>
</module>
我在 jboss-eap-6.3 文件夹中搜索了冲突的 jar。但是,BodyTagSupport class 仅存在于 jsp-api-2.1.jar 和 jboss-jsp-api_2.2_spec-1.0.1.Final-红帽-2.jar。而且两个罐子都兼容。
那么,为什么我得到 ClassCastException?
在module.xml
文件中添加<module name="javax.servlet.jsp.api"/>
依赖后解决,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com">
<resources>
...
<resource-root path="jsp-api-2.1.jar"/>
...
</resources>
<dependencies>
<module name="sun.jdk"/>
<module name="javax.api"/>
<module name="javax.servlet.api"/>
<module name="javax.servlet.jsp.api"/>
<module name="org.jboss.logging"/>
<module name="org.jboss.modules"/>
</dependencies>
</module>
但是,我不明白,模块的资源根路径中已经添加了jsp-api-2.1.jar
,为什么还要为javax.servlet.jsp.api
添加依赖。
在 JBoss 服务器中部署包含自定义标记的 Web 应用程序出现以下异常:
java.lang.ClassCastException: com.test.taglib.MyCustomTag cannot be cast to javax.servlet.jsp.tagext.Tag
at org.apache.jasper.runtime.PerThreadTagHandlerPool.get(PerThreadTagHandlerPool.java:96) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.jsp.WEB_002dINF.jsp.testAppData_jsp._jspx_meth_fx_005fsystemDate_005f0(testAppData_jsp.java:725)
at org.apache.jsp.WEB_002dINF.jsp.testAppData_jsp._jspService(testAppData_jsp.java:150)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:69) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:365) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:309) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:242) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:832) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:620) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:553) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:482) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238) [org.springframework.web.servlet-3.0.7.RELEASE.jar:3.0.7.RELEASE]
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250) [org.springframework.web.servlet-3.0.7.RELEASE.jar:3.0.7.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1047) [org.springframework.web.servlet-3.0.7.RELEASE.jar:3.0.7.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817) [org.springframework.web.servlet-3.0.7.RELEASE.jar:3.0.7.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719) [org.springframework.web.servlet-3.0.7.RELEASE.jar:3.0.7.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:669) [org.springframework.web.servlet-3.0.7.RELEASE.jar:3.0.7.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:574) [org.springframework.web.servlet-3.0.7.RELEASE.jar:3.0.7.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
我的自定义标签 class
public class MyCustomTag extends BodyTagSupport {
...
}
MyCustomTag 间接继承 Tag class:MyCustomTag -> BodyTagSupport -> BodyTag -> IterationTag -> Tag
所有标签classes被打包成jsp-api-2.1.jar并包含在module.xml中,如下图:
module.xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com">
<resources>
...
<resource-root path="jsp-api-2.1.jar"/>
...
</resources>
<dependencies>
<module name="sun.jdk"/>
<module name="javax.api"/>
<module name="javax.servlet.api"/>
<module name="org.jboss.logging"/>
<module name="org.jboss.modules"/>
</dependencies>
</module>
我在 jboss-eap-6.3 文件夹中搜索了冲突的 jar。但是,BodyTagSupport class 仅存在于 jsp-api-2.1.jar 和 jboss-jsp-api_2.2_spec-1.0.1.Final-红帽-2.jar。而且两个罐子都兼容。
那么,为什么我得到 ClassCastException?
在module.xml
文件中添加<module name="javax.servlet.jsp.api"/>
依赖后解决,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com">
<resources>
...
<resource-root path="jsp-api-2.1.jar"/>
...
</resources>
<dependencies>
<module name="sun.jdk"/>
<module name="javax.api"/>
<module name="javax.servlet.api"/>
<module name="javax.servlet.jsp.api"/>
<module name="org.jboss.logging"/>
<module name="org.jboss.modules"/>
</dependencies>
</module>
但是,我不明白,模块的资源根路径中已经添加了jsp-api-2.1.jar
,为什么还要为javax.servlet.jsp.api
添加依赖。