简体   繁体   English

尝试访问Tomcat上已部署的战争时获取HTTP状态404

[英]Get HTTP Status 404 when trying to access deployed war on Tomcat

SOLVED: I converted the application from spring-boot to standard spring mvc and it now works. 已解决:我将应用程序从spring-boot转换为标准spring mvc,现在可以使用了。 Thanks for everyone who tried to help. 感谢所有尝试提供帮助的人。 Still not sure what the issue was but I've got it working now. 仍然不确定问题是什么,但我现在已经开始解决了。


I'm trying to deploy webapps to tomcat 7. The apps are built using spring-boot and packaged using maven. 我正在尝试将Web应用程序部署到tomcat7。这些应用程序是使用spring-boot构建的,并使用maven打包。

I am placing the wars in the webapps folder and it is being deployed successfully: 我将战争放在webapps文件夹中,并且已成功部署:

Jul 31, 2015 1:22:05 PM org.apache.catalina.startup.HostConfigdeployWAR 2015年7月31日,下午1:22:05 org.apache.catalina.startup.HostConfigdeployWAR

INFO: Deploying web application archive /var/lib/tomcat7/webapps/application.war INFO:部署Web应用程序归档文件/var/lib/tomcat7/webapps/application.war

Jul 31, 2015 1:22:09 PM org.apache.catalina.startup.HostConfig deployWAR 2015年7月31日1:22:09 PM org.apache.catalina.startup.HostConfig deployWAR

INFO: Deploying web application archive /var/lib/tomcat7/webapps/Application.war 信息:部署Web应用程序存档/var/lib/tomcat7/webapps/Application.war

Jul 31, 2015 1:22:10 PM org.apache.catalina.startup.HostConfig deployDirectory 2015年7月31日1:22:10 PM org.apache.catalina.startup.HostConfig deployDirectory

INFO: Deploying web application directory /var/lib/tomcat7/webapps/ROOT INFO:部署Web应用程序目录/ var / lib / tomcat7 / webapps / ROOT

Jul 31, 2015 1:22:11 PM org.apache.coyote.AbstractProtocol start 2015年7月31日,下午1:22:11 org.apache.coyote.AbstractProtocol开始

INFO: Starting ProtocolHandler ["http-bio-8080"] INFO:启动ProtocolHandler [“ http-bio-8080”]

Jul 31, 2015 1:22:11 PM org.apache.catalina.startup.Catalina start 2015年7月31日1:22:11 PM org.apache.catalina.startup.Catalina开始

INFO: Server startup in 6796 ms INFO:服务器在6796毫秒内启动

However, when I try to access them through the browser I get a 404 message (The requested resource is not available.). 但是,当我尝试通过浏览器访问它们时,我收到一条404消息(请求的资源不可用。)。 I can see the ROOT index and get to the manager app, where they are correctly identified as Spring MVC and I am told they are deployed and running. 我可以看到ROOT索引并转到管理器应用程序,在该应用程序中将它们正确标识为Spring MVC,并告知它们已部署并正在运行。 Clicking on the link within the manager gives me the same result. 单击管理器中的链接可以得到相同的结果。 catalina.out isn't telling me anything. catalina.out没告诉我任何事情。 It doesn't give me anymore information after the server startup message. 服务器启动消息后,它不再向我提供任何信息。

EDIT WITH MORE INFO This is the web.xml for the application 编辑更多信息这是应用程序的web.xml

<web-app version="3.0" 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">

    <display-name>Spring MVC Application</display-name>

    <servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>

Controller handling index requests: 控制器处理索引请求:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/")
/**
 * Default Controller.
 */
class HelloController {
    /**
     * Implementation of logging interface in SL4J.
     */
    private static final Logger LOGGER = LoggerFactory.getLogger
            (HelloController.class);

    /**
     * Constructs a new Hello Controller
     */
    public HelloController() {
        LOGGER.trace("Created hello controller");
    }

    /**
     * Prints the message on the screen
     * @param model the model to add the message too
     * @return a String
     */
    @RequestMapping(method = RequestMethod.GET)
    public String printWelcome(final ModelMap model) {
        model.addAttribute("message", "Hello world!");
        return "hello";
    }
}

The urls I am trying to access are http://localhost:8080/application/ and http://localhost:8080/Application/ 我尝试访问的URL是http:// localhost:8080 / application /http:// localhost:8080 / Application /

I have also tried it in Tomcat 8 and get the same issue. 我也曾在Tomcat 8中尝试过并得到相同的问题。 I tried copying the ROOT folder and renaming the copy to application and can access that fine. 我尝试复制ROOT文件夹并将其重命名为应用程序,并且可以正常访问。 Seems to be something with the war? 似乎与战争有关?

<web-app version="3.0" 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">

Try using the latest web app version and make sure to check the spellings very carefully or missing tags. 尝试使用最新的网络应用版本,并确保非常仔细地检查拼写或缺少标签。

It seems like the application is deployed under ROOT context. 看来该应用程序是在ROOT上下文下部署的。 This will be the case if the context path is empty string. 如果上下文路径为空字符串,则将是这种情况。 for ex: 例如:

<Context path="" docBase="${catalina.home}/webapps/application.war" >

So your application should be available on "http:localhost:8080/". 因此,您的应用程序应该在“ http:localhost:8080 /”上可用。 If you want the application to be available on "http:localhost:8080/applicaiton" then there are 2 ways: 如果您希望该应用程序在“ http:localhost:8080 / applicaiton”上可用,则有两种方法:

  1. If you are defining " <Context> " element in server.xml, then define it as : <Context path="/application" docBase="${catalina.home}/webapps/application.war"> 如果要在server.xml中定义“ <Context> ”元素,则将其定义为: <Context path="/application" docBase="${catalina.home}/webapps/application.war">

  2. As per below documentation, you need to add a context xml by name "application.xml" in your host directory of the server.For ex - " {catalina.base}/conf/Catalina/localhost/application.xml " https://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Naming 按照下面的文档,您需要在服务器的主机目录中添加名称为“ application.xml”的上下文xml。例如-“ {catalina.base}/conf/Catalina/localhost/application.xmlhttps:/ /tomcat.apache.org/tomcat-7.0-doc/config/context.html#Naming

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从Spring拦截器打印时HTTP状态错误(0)-在独立TOMCAT中将应用程序部署为WAR时 - Wrong HTTP Status (0) when printing it from a Spring interceptor - When application is deployed as WAR in standalone TOMCAT Tomcat在尝试登录时给出HTTP状态404 - Tomcat gives HTTP Status 404 when trying to log in HTTP状态404-tomcat 7 - HTTP Status 404 - tomcat 7 Tomcat - 如果没有正确部署应用程序,如何获取http 500而不是404? - Tomcat - how to get http 500 instead of 404 when application wasn't deployed correctly? HTTP 状态 404:Tomcat 服务器启动但在 Bowser 中出现 404 错误 - HTTP Status 404 : Tomcat server starts but in the bowser get 404 error 当使用Eclipse在Glassfish上重命名和部署动态Web项目的名称时,获取HTTP状态404 - 未找到 - Get HTTP Status 404 - Not Found, when the name of a dynamic web project renamed and deployed on Glassfish with Eclipse 404在将WAR部署到tomcat时 - 404 when deploying WAR to tomcat Tomcat9 应用程序状态为 false 并在尝试访问服务器路径时抛出 404 - Tomcat9 application status is false and throwing 404 when trying to access the server path HTTP状态404 Eclipse Tomcat 7 - HTTP Status 404 Eclipse Tomcat 7 HTTP tomcat maven 上的 WAR 文件部署后状态 404,即使我的项目运行良好 - HTTP Status 404 after WAR file deployment on tomcat maven even my project is working fine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM