【问题标题】:IBM BlueMix | While adding jsf : The application or context root for this request has not been found: ./?IBM BlueMix |添加 jsf 时:未找到此请求的应用程序或上下文根:./?
【发布时间】:2016-08-03 01:58:38
【问题描述】:

我有一个在 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>

【问题讨论】:

  • 能否请您指定您正在调用的 URL 以及您在 jsf 应用程序中使用的 web.xml?
  • @v.bontempi 我用 web.xml 更新了这个问题,很抱歉我不能分享这个 url,因为我现在使用 jee 依赖项让它工作了......不会增值! ...你知道为什么它适用于 jee jar 而不是 jsf jar

标签: java jsf ibm-cloud websphere-liberty


【解决方案1】:

检查您的 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 网络服务正在监听 /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 作为依赖

它会解决你的问题

【讨论】:

  • 你能澄清一下吗?我已经在使用具有相同 web.xml 的 jee jar 并且它运行良好....
  • “使用带有相同 web.xml 的 jee jar”是什么意思?这个应用程序在哪里运行?
  • 请查看我的问题.....该应用程序正在破坏 bluemix,jsf 仅在使用 pom 文件中的 Jee 依赖项时才有效,当使用 pom 文件中的问题中提到的 jsf 依赖项时它没有t 工作 .... 和 web.xml 中具有相同面孔 serlvet 映射的两种情况
  • 我格式化了你的问题,现在上下文很清楚了。问题不在于 JSF,而是您在 web.xml 中配置的 servlet 添加 JSF 依赖项时是否使用相同的 web.xml?
  • 编辑需要被接受。问题在于您的 web.xml 路径配置。我不明白你为什么对答案投了反对票。
【解决方案2】:

我找到了答案Here

简述

如果您使用的是 Maven,您可以在下方找到必要的坐标:

Java EE 容器(WildFly、JBoss、TomEE、Payara、GlassFish、WebSphere 等)

<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-web-api</artifactId>
    <version><!-- 7.0 (JSF 2.2) or 6.0 (JSF 2.0/2.1) --></version>
    <scope>provided</scope>
</dependency>

请注意,Java EE 版本必须与服务器自己的 Java EE 版本匹配。在面向 Java EE 6 服务器时,不能将其设置为 7.0。

Servlet 容器(Tomcat、Jetty 等)

莫哈拉

<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>javax.faces</artifactId>// jsf-imp and jsf-api were been mereged into one jar 
    <version><!-- Check http://javaserverfaces.java.net --></version>
</dependency>
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    <version>1.2</version>
</dependency>

您还可以查看 org.glassfish:javax.faces 存储库以获取当前最新的 Mojarra 发布版本(截至目前为 2.2.13)。

我的面孔

<dependency>
    <groupId>org.apache.myfaces.core</groupId>
    <artifactId>myfaces-api</artifactId>
    <version><!-- Check http://myfaces.apache.org --></version>
</dependency>
<dependency>
    <groupId>org.apache.myfaces.core</groupId>
    <artifactId>myfaces-impl</artifactId>
    <version><!-- Check http://myfaces.apache.org --></version>
</dependency>
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    <version>1.2</version>
</dependency>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-12
    • 2017-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多