WildFly 9 部署简单的 webapp 但 404

WildFly 9 deploying simple webapp but 404

我有一个简单的 hello world web 应用程序,当我 运行 它在 tomcat 和 url http://localhost:8080/na/environment 中工作正常;同样的war在wildfly 9里不行,我得到404错误。

谷歌搜索我发现一个 WildFly 项目需要 2 个文件(beans.xml 和 jboss-web.xml),我刚刚添加到该项目但仍然无法正常工作。

我的 wildldFly 管理控制台显示 war 已部署并启用

这是我项目的结构:

而我的文件jboss-web.xml的内容是:

<?xml version="1.0" encoding="UTF-8"?>
 <jboss-web xmlns="http://www.jboss.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd">
  <context-root>/</context-root>
 </jboss-web>

beans.xml是空的(还是不明白它的海豚是什么)

最后,我的 servlet(而且只有 class)的代码是:

@WebServlet(urlPatterns="/environment")
public class Environment extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request,
                         HttpServletResponse response) throws ServletException,
                                                       IOException {
    response.getWriter().append("Hello");
    }

    protected void doPost(HttpServletRequest request,
                          HttpServletResponse response) throws ServletException,
                                                        IOException {
    doGet(request, response);
    }



}

我尝试使用:

http://localhost:9990/na/environment/
http://localhost:9990/na.war/environment/
http://localhost:9990/environment/

如果您希望上下文是 na,您需要更改 jboss-web.xml 以使用 na 作为根上下文。

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web xmlns="http://www.jboss.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd">
    <context-root>/na</context-root>
</jboss-web>   

如果您在部署时更改运行时名称,那也应该有效。您也可以覆盖 pom 中的 <finalName>na</finalName>