Jetty:启动webapp时显示404页面

时间:2017-09-13 11:04:25

标签: java spring jetty

我正在尝试使用Jetty作为应用程序容器来运行基于Spring-MVC的应用程序。不幸的是,当我启动应用程序时,我得到了404页面。我究竟做错了什么? Jetty版本:9.4:

屏幕截图:

enter image description here

记录:

/usr/lib/jvm/java-8-oracle/bin/java -DSTOP.PORT=0 -Dcom.sun.management.jmxremote= -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -DOPTIONS=jmx -Didea.launcher.port=7537 -Didea.launcher.bin.path=/home/akshay/Downloads/idea136/bin -Dspring.security.strategy=MODE_INHERITABLETHREADLOCAL -Dfile.encoding=UTF-8 -classpath start.jar:/usr/lib/jvm/java-8-oracle/lib/tools.jar:/home/akshay/Downloads/idea136/lib/idea_rt.jar com.intellij.rt.execution.application.AppMain org.eclipse.jetty.start.Main --module=jmx,slf4j-log4j,session-store-gcloud /tmp/context7601552538379376293config/jetty-contexts.xml
Detected server http port: 8080
[2017-09-13 04:27:32,863] Artifact webappname:war exploded: Server is not connected. Deploy is not available.
2017-09-13 16:27:33.429:INFO::main: Logging initialized @124ms to org.eclipse.jetty.util.log.StdErrLog
2017-09-13 16:27:33.646:WARN:oejs.HomeBaseWarning:main: This instance of Jetty is not running from a separate {jetty.base} directory, this is not recommended.  See documentation at http://www.eclipse.org/jetty/documentation/current/startup.html
2017-09-13 16:27:33.773:INFO:oejs.Server:main: jetty-9.4.6.v20170531
2017-09-13 16:27:33.797:INFO:oejdp.ScanningAppProvider:main: Deployment monitor [file:///home/akshay/Downloads/jetty-distribution-9.4.6.v20170531/webapps/] at interval 1
2017-09-13 16:27:33.800:INFO:oejdp.ScanningAppProvider:main: Deployment monitor [file:///tmp/context4442083180054405388deploy/] at interval 1
2017-09-13 16:27:33.815:INFO:oejs.session:main: DefaultSessionIdManager workerName=node0
2017-09-13 16:27:33.815:INFO:oejs.session:main: Scavenging every 600000ms
2017-09-13 16:27:33.884:INFO:oejs.AbstractConnector:main: Started ServerConnector@3c756e4d{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
2017-09-13 16:27:33.885:INFO:oejs.Server:main: Started @581ms

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
          http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0">
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/root-context.xml,/WEB-INF/spring/appServlet/security-applicationContext.xml
        </param-value>

    </context-param>

    <session-config>
        <session-timeout>0</session-timeout>
        <tracking-mode>COOKIE</tracking-mode>
    </session-config>
    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>

    <distributable/>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <filter>
        <filter-name>cross-origin</filter-name>
        <filter-class>org.eclipse.jetty.servlets.CrossOriginFilter</filter-class>
        <async-supported>true</async-supported>

    </filter>
    <filter-mapping>
        <filter-name>cross-origin</filter-name>
        <url-pattern>/cometd/*</url-pattern>
    </filter-mapping>

    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
        <async-supported>true</async-supported>
        <init-param>
            <param-name>contextAttribute</param-name>
            <param-value>org.springframework.web.context.WebApplicationContext.ROOT</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <servlet>
        <async-supported>true</async-supported>
        <servlet-name>403Jsp</servlet-name>
        <jsp-file>/WEB-INF/views/error/403.jsp</jsp-file>
    </servlet>
    <servlet-mapping>
        <servlet-name>403Jsp</servlet-name>
        <url-pattern>/403</url-pattern>
    </servlet-mapping>
    <listener>
        <listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
    </listener>
    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
        <async-supported>true</async-supported>
    </servlet>
    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

有什么想法吗?谢谢。

1 个答案:

答案 0 :(得分:0)

在下面的web.xml部分中,定义要加载为主页的文件。

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

现在,您说,您在应用程序根文件夹中没有任何文件除了readme.txt,那么您希望加载什么内容?

您需要确保:

  1. 您的网络应用已正确部署,并且至少包含welcome-file-list
  2. 中列出的任何文件
  3. 您需要访问http://localhost:8080/<yourwebapp>