我的欢迎文件在 Open Liberty 中返回一个空白页面 web.xmlserver.xml附加信息解决方案想法

问题描述

在 Open Liberty 21.0.0.6. 上,当我将其指向 http://<host>:<port>/<ctxRoot> 时,浏览器不会显示我的欢迎 JSF 页面,而是返回空内容

web.xml

<web-app id="WebApp_ID" version="4.0"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd">

  <display-name>MyJSF</display-name>

  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
  </servlet-mapping>

   <welcome-file-list>
      <welcome-file>index.xhtml</welcome-file>
    </welcome-file-list>

</web-app>

和一组功能

server.xml

<server>
  <featureManager>
    <feature>jaxrs-2.1</feature>
    <feature>cdi-2.0</feature>
    <feature>jpa-2.2</feature>
    <feature>jdbc-4.3</feature>
    <feature>jsf-2.3</feature>
    <feature>mpHealth-3.0</feature>
  </featureManager>

附加信息

我的应用中还有一些其他内容,例如 JPA 和 JAX-RS。

解决方法

根本原因 - 带有“/”应用程序路径的 JAX-RS 应用程序

就我而言,问题是我将 JAX-RS 应用程序配置为使用:@ApplicationPath("/"),这与我让“/”应用程序路径提供欢迎文件的目标相冲突。

解决方案

将 JAX-RS 应用移动到它自己在 WAR 中的路径,例如:

import javax.ws.rs.core.Application;

@ApplicationPath("/api")
public class TestApp extends Application { }

想法

通过将现有的简单 JAX-RS 应用程序使用“/”作为应用程序路径,然后向其中添加 JSF,很容易发现这种情况。然后我以为我在 JSF 实现上遇到了问题。