H5W3
当前位置:H5W3 > 其他技术问题 > 正文

javaweb项目在Eclipse中启动Tomcat后运行正常,但是打成war包启动后运行异常的问题?

项目框架

SSM+redis+shiro


问题描述

Eclipse中启动项目

从“Start the server”启动,项目运行一切正常

image.png

war包启动

项目打包,将war包放入本地Tomcat下/webapps目录,运行bin/startup.bat,命令行窗口显示启动成功,且无任何报错信息,日志文件也无任何报错。浏览器访问localhost:8005/项目名,页面前端文件拉取正常,但和后端相关的请求全部404报错
image.png
image.png
如:网站图标favicon.ico以及尝试进行登录操作(URI:/login),皆返回404错误


catalina.2019-11-24.log日志

24-Nov-2019 20:19:35.269 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/8.5.30
24-Nov-2019 20:19:35.272 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Apr 3 2018 20:04:09 UTC
24-Nov-2019 20:19:35.272 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:         8.5.30.0
24-Nov-2019 20:19:35.272 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Windows 7
24-Nov-2019 20:19:35.272 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            6.1
24-Nov-2019 20:19:35.273 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
24-Nov-2019 20:19:35.273 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             C:\Program Files\Java\jdk1.8.0_60\jre
24-Nov-2019 20:19:35.273 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.8.0_60-b27
24-Nov-2019 20:19:35.273 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation
24-Nov-2019 20:19:35.274 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         C:\apache-tomcat-8.5.30
24-Nov-2019 20:19:35.274 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         C:\apache-tomcat-8.5.30
24-Nov-2019 20:19:35.274 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=C:\apache-tomcat-8.5.30\conf\logging.properties
24-Nov-2019 20:19:35.274 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
24-Nov-2019 20:19:35.274 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
24-Nov-2019 20:19:35.274 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
24-Nov-2019 20:19:35.274 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
24-Nov-2019 20:19:35.275 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=C:\apache-tomcat-8.5.30
24-Nov-2019 20:19:35.275 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=C:\apache-tomcat-8.5.30
24-Nov-2019 20:19:35.275 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=C:\apache-tomcat-8.5.30\temp
24-Nov-2019 20:19:35.275 信息 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library [1.2.16] using APR version [1.6.3].
24-Nov-2019 20:19:35.276 信息 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
24-Nov-2019 20:19:35.276 信息 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
24-Nov-2019 20:19:35.807 信息 [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.0.2m  2 Nov 2017]
24-Nov-2019 20:19:35.891 信息 [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8005"]
24-Nov-2019 20:19:35.943 信息 [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
24-Nov-2019 20:19:35.947 信息 [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8011"]
24-Nov-2019 20:19:35.954 信息 [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
24-Nov-2019 20:19:35.957 信息 [main] org.apache.catalina.startup.Catalina.load Initialization processed in 935 ms
24-Nov-2019 20:19:35.975 信息 [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
24-Nov-2019 20:19:35.975 信息 [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.30
24-Nov-2019 20:19:36.195 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [C:\apache-tomcat-8.5.30\webapps\ReportOA-0.0.1-SNAPSHOT.war]
24-Nov-2019 20:19:36.282 警告 [localhost-startStop-1] org.apache.tomcat.util.descriptor.web.WebXml.setVersion Unknown version string [4.0]. Default version will be used.
24-Nov-2019 20:19:38.839 信息 [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
24-Nov-2019 20:19:44.646 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [C:\apache-tomcat-8.5.30\webapps\ReportOA-0.0.1-SNAPSHOT.war] has finished in [8,451] ms
24-Nov-2019 20:19:44.648 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\apache-tomcat-8.5.30\webapps\docs]
24-Nov-2019 20:19:44.681 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\apache-tomcat-8.5.30\webapps\docs] has finished in [33] ms
24-Nov-2019 20:19:44.683 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\apache-tomcat-8.5.30\webapps\examples]
24-Nov-2019 20:19:44.980 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\apache-tomcat-8.5.30\webapps\examples] has finished in [297] ms
24-Nov-2019 20:19:45.003 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\apache-tomcat-8.5.30\webapps\host-manager]
24-Nov-2019 20:19:45.019 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\apache-tomcat-8.5.30\webapps\host-manager] has finished in [17] ms
24-Nov-2019 20:19:45.019 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\apache-tomcat-8.5.30\webapps\manager]
24-Nov-2019 20:19:45.033 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\apache-tomcat-8.5.30\webapps\manager] has finished in [14] ms
24-Nov-2019 20:19:45.042 信息 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8005"]
24-Nov-2019 20:19:45.060 信息 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8011"]
24-Nov-2019 20:19:45.078 信息 [main] org.apache.catalina.startup.Catalina.start Server startup in 9121 ms

附一张刷新网页后命令行窗口截图:
image.png


该问题一般由哪些情况产生?我该向哪个方向去寻找解决办法?

回答:

向后端请求的路径错误

可能是(因为我们之前如果写的是绝对路径是8080端口是本地的tomcat,我们需要改成                        ${pageContext.request.contextPath} 项目的相对路径,这样就可以不用受到,本地和非本地的影响了)

本文地址:H5W3 » javaweb项目在Eclipse中启动Tomcat后运行正常,但是打成war包启动后运行异常的问题?

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址