我有一个使用 JSF 2 在 JBoss 上运行良好的应用程序。我看到了与 JSF 2、WebSphere 和类加载器相关的问题。此时,我看到消息“Initializing Mojarra 2.1.7 for the context '/medicao-web'”。然后,我认为类加载器正在加载正确的 JSF 类。
我有一个用于重定向到 index.jsf 的 index.jsp。当我尝试请求 index.jsf 时,它会产生无限循环和很多异常。在堆栈跟踪中,有一个“at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)”,然后我认为它有时会使用 FacesServlet。但我还在日志中看到与 JSF 相关的问题是它正在尝试读取 JSP。
我还尝试请求一个不同的页面,即没有同名的 JSP。请求 arquivo.jsf 后,我得到:
java.io.FileNotFoundException: JSPG0036E: Failed to find resource /arquivo.jsp
at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionProcessor.findWrapper(AbstractJSPExtensionProcessor.java:360)
at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionProcessor.handleRequest(AbstractJSPExtensionProcessor.java:331)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:325)
at com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:415)
at com.sun.faces.application.ViewHandlerImpl.executePageToBuildView(ViewHandlerImpl.java:491)
at com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:159)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1443)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1384)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:131)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:188)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:116)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:77)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:852)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:785)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:443)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:175)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3610)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:274)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:926)
at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1557)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:173)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:455)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:384)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:272)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:202)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:766)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:896)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1527)
这是我的 web.xml:
<?xml version="1.0"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>MedicaoCNI</display-name>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>medicao</param-value>
</context-param>
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
</web-app>
这是我的 faces-config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">
<!-- <lifecycle>
<phase-listener>org.cni.medicao.util.AuthenticationListener</phase-listener>
</lifecycle> -->
<navigation-rule>
<from-view-id>/*</from-view-id>
<navigation-case>
<from-outcome>loginSucesso</from-outcome>
<to-view-id>/usuario.jsf</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>loginFail</from-outcome>
<to-view-id>/index.jsf</to-view-id>
<redirect />
</navigation-case>
<navigation-case>
<from-outcome>logoutSucesso</from-outcome>
<to-view-id>/index.jsf</to-view-id>
<redirect />
</navigation-case>
</navigation-rule>
</faces-config>
我所有的页面都是 XHTML 格式。我还在我的项目中添加了一个 facelets 依赖项。我正在使用Maven。
我做了一些配置来尝试让类加载器加载 PARENT_LAST。我不知道它是否正确,但是虽然日志说它正在加载 Mojarra 2.1.7,但我认为没关系。
我找到了一篇与我相关的帖子,但没有解决:JSF 2 Mojarra and Primefaces in WebSphere 7+
提前致谢。
更新:
我尝试将 javax.faces.DEFAULT_SUFFIX 上下文参数添加到 .xhtml。结果是,当我尝试打开 arquivo.jsf 时,我看到了 XHTML 的源代码。虽然日志说它正在初始化 Mojarra 2.1.7,但我觉得这里有一些冲突。
这是我耳朵的maven模块的耳朵插件配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.6</version>
<configuration>
<version>5</version>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<earSourceDirectory>${basedir}\src\main\application\META-INF\ibmconfig</earSourceDirectory>
</configuration>
</plugin>
在\src\main\application\META-INF\ibmconfig,有deployment.xml:
<appdeployment:Deployment xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:appdeployment="http://www.ibm.com/websphere/appserver/schemas/5.0/appdeployment.xmi" xmi:id="Deployment_1241112964096">
<deployedObject xmi:type="appdeployment:ApplicationDeployment" xmi:id="ApplicationDeployment_1241112964096" startingWeight="1" warClassLoaderPolicy="SINGLE">
<classloader xmi:id="Classloader_1241112964096" mode="PARENT_LAST"/>
<modules xmi:type="appdeployment:WebModuleDeployment" xmi:id="WebModuleDeployment_1241112964096" startingWeight="10000" uri="medicao-web.war">
<classloader xmi:id="Classloader_1241112964097" mode="PARENT_LAST"/>
</modules>
</deployedObject>
</appdeployment:Deployment>
在我的 web 的 maven 模块中,我有这个依赖项:
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1.7</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.1.7</version>
</dependency>
<dependency>
<groupId>com.sun.facelets</groupId>
<artifactId>jsf-facelets</artifactId>
<version>1.1.14</version>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>3.2</version>
<scope>compile</scope>
</dependency>
有什么不对?我是 WebSphere 新手,我需要将它与 JSF 2 一起使用。
更新:
我删除了 jsf-facelets 依赖项,但它还没有工作。我导出了一个 EAR 以查看 deployment.xml 是否存在,但它没有被打包在 EAR 中。有什么不对?
更新:
我的deployment.xml在\META-INF\ibmconfig\cells\defaultCell\applications\defaultApp\deployments\defaultApp下,我的ear插件的配置是:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.6</version>
<configuration>
<version>5</version>
<defaultLibBundleDir>lib</defaultLibBundleDir>
</configuration>
</plugin>
这样,当我导出 EAR 时,deployment.xml 就会被打包。我的 deployment.xml 与教程中显示的相同。
无论如何,当我在 WebSphere 上部署我的应用程序时,它会生成一个新的 deployment.xml,而忽略我的。然后,它仍然首先加载父级。