gpt4 book ai didi

java - IBM BlueMix | IBM BlueMix | IBM BlueMix同时添加 jsf : The application or context root for this request has not been found: ./?

转载 作者:行者123 更新时间:2023-12-01 10:04:12 26 4
gpt4 key购买 nike

我有一个在 IBM Bluemix 上运行的简单 JSF 应用程序,与以下 J2EE 依赖项配合良好。

<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>

用 JSF 依赖项替换它时

<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.2</version>
</dependency>

我收到以下错误

尚未找到此请求的应用程序或上下文根:/

有什么帮助吗?

我的 Web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app 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_3_0.xsd"
version="3.0">

<display-name>Java DB Web Starter</display-name>
<servlet>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>

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

<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<!-- Map these files with JSF -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

<persistence-context-ref>
<persistence-context-ref-name>openjpa-todo/entitymanager</persistence-context-ref-name>
<persistence-unit-name>openjpa-todo</persistence-unit-name>
</persistence-context-ref>

<resource-ref>
<!-- The cloudAutowiring-1.0 Liberty feature will resolve this to whatever
the database service name is -->
<!-- When running locally without this feature, create a datasource with
the JNDI name "jdbc/mydbdatasource" in server.xml -->
<!-- If using MySQL locally then use the "url" property and append "?relaxAutoCommit=true", for example:
<dataSource id='mysql-datasource' jdbcDriverRef='mysql-driver' jndiName='jdbc/mydbdatasource'>
<properties user='root' password='password' url="jdbc:mysql://localhost:3306/db?relaxAutoCommit=true"/>
</dataSource> -->
<res-ref-name>jdbc/mydbdatasource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</web-app>

最佳答案

检查您的 web.xml,您应该使用调用您的应用程序

https://[your_application_URL]/faces/

而不是

https://[your_application_URL]/

因为 Faces Servlet 正在根据该路径监听

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

以同样的方式,jax-rs Web服务根据/api 路径监听

<servlet-mapping>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>

讨论问题后编辑:

问题出在使用的 jsf 依赖项上,这使得应用程序使用包含 java 包 com.sun.faces 下的类的 jsf-impl-xxx.jar,而不是使用 jsf 加载的包 javax.faces 下的类-api-xxx.jar(使用j2ee-web-api依赖时使用)最后一个 jar 中的类是 JSF 规范定义的标准 API 的实现。

如果您只想添加 JSF 的依赖项,而不携带整个 j2ee-web-api,您可以使用这些工件jsf-api-xxx 作为依赖项

它会解决你的问题

关于java - IBM BlueMix | IBM BlueMix | IBM BlueMix同时添加 jsf : The application or context root for this request has not been found: ./?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36573551/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com