【问题标题】:Wildfly App - can't serve static contentWildfly 应用程序 - 无法提供静态内容
【发布时间】:2018-09-28 19:14:03
【问题描述】:

我正在开发 Wildfly 应用程序项目,但遇到了问题。 我已经配置了 web.xml,并且在 webapp 文件夹中我有一个 index.html 文件。 起初页面工作页面,每次我去:“localhost/myapp/”它都会向我显示页面。 但是服务器任意决定不再向我提供该页面,现在每次我尝试访问该页面时,我都会得到一个空白页面。 即使我尝试直接访问资源,我也会得到一个空白页: “localhost/myapp/index.html”。

在控制台我有这个堆栈跟踪:

15:50:19,729 ERROR [org.jboss.resteasy.resteasy_jaxrs.i18n] (default task-12) RESTEASY002010: Failed to execute: javax.ws.rs.NotFoundException: RESTEASY003210: Could not find resource for full path: http://localhost:8080/jboss-helloworld-html5/
at org.jboss.resteasy.core.registry.ClassNode.match(ClassNode.java:75)
at org.jboss.resteasy.core.registry.RootClassNode.match(RootClassNode.java:48)
at org.jboss.resteasy.core.ResourceMethodRegistry.getResourceInvoker(ResourceMethodRegistry.java:445)
at org.jboss.resteasy.core.SynchronousDispatcher.getInvoker(SynchronousDispatcher.java:257)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:194)
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:221)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:284)
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:263)
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:174)
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:793)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

Web.xml:

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">
 <servlet-mapping>
  <servlet-name>javax.ws.rs.core.Application</servlet-name>
  <url-pattern>/*</url-pattern>
 </servlet-mapping>
 <welcome-file-list>
  <welcome-file>index.html</welcome-file>
 </welcome-file-list>
</web-app>

【问题讨论】:

  • 您是否尝试使用 RESTful/RESTEasy,因为 JBoss 似乎认为您的应用程序是 RESTFul 应用程序?
  • 我正在使用基于“jboss-helloworld-html5”示例的restful/resteasy servlet。您需要其他文件吗?
  • 你能用 web.xml 内容更新你的问题吗?到目前为止,您是否对 jboss-helloworld-html5 进行了任何修改,我想说我可以尝试一下 - 请注意我使用的是 JBoss EAP 7,但我相信它基于 WildFly 10
  • 已更新。没有,没那么多,只是添加了一些包导入,新建了一个restful服务,但是一开始就出现了这个问题。
  • 我猜但很确定这是导致它的原因&lt;url-pattern&gt;/*&lt;/url-pattern&gt; 这基本上是说我希望所有内容都映射(发送)到该 servlet,因此可能会覆盖欢迎文件列表。尝试更具体地使用 servlet 的 URL,例如 &lt;url-pattern&gt;/MyServlet&lt;/url-pattern&gt; - 让我给你找个例子

标签: jboss wildfly wildfly-10


【解决方案1】:

我相信您的 URL 模式正在吞噬所有内容,包括对静态 html 页面的请求。您的 web.xml 应如下所示,注意“hello”可以更改为您喜欢的任何内容,但必须与您在浏览器中放置的内容相匹配,因此浏览器中的地址将为 http://localhost:8080/hello/

<web-app version="3.1" 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_3_1.xsd">
    <!-- One of the ways of activating REST Services is adding these lines.
         The server is responsible for adding the corresponding servlet automatically.
         The class org.jboss.as.quickstarts.html5rest.HelloWorld class has the
         annotation @Path("/") to receive the REST invocation -->
    <servlet-mapping>
        <servlet-name>javax.ws.rs.core.Application</servlet-name>
        <url-pattern>/hello/*</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
</web-app>

静态文件可能可以通过以下方式访问:
http://localhost:8080/
要么
http://localhost:8080/index.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-24
    • 2020-06-26
    • 2016-05-02
    • 1970-01-01
    • 2010-11-30
    • 2018-01-29
    • 1970-01-01
    相关资源
    最近更新 更多