【发布时间】:2016-01-09 07:12:25
【问题描述】:
部署在我的 Tomcat 上的每个应用程序都会在我发出的每个请求上返回 status code 404。我尝试了几个项目,helloworlds 或骨架,每个项目的行为都与其他项目相同:
我使用过的一些项目:
https://github.com/mwarman/skeleton-ws-spring-boot
https://spring.io/guides/gs/rest-service/(我可以使用 mvn spring-boot:run 运行它,但它在部署到 Tomcat 时不起作用)
https://github.com/shagstrom/spring-mvc-hibernate-skeleton
我正在使用最新的Tomcat8 (8.0.27)、Oracle JDK 8。我也试过Tomcat7 和OpenJDK 7。
使用过的 Tomcat 在 MAC 和 Debian 上运行。
我通过 mvn 和 Intellij Idea 构建了应用程序。
Tomcat 是干净的,没有更改任何配置(添加 manager-gui 用户除外)。
由于我尝试了许多不同的项目,我认为问题不在于代码。它在Tomcat的配置中吗?我怎样才能让它工作?
编辑:
server.xml代码:
<?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<!--APR library loader. Documentation at /docs/apr.html -->
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<!-- Global JNDI resources
Documentation at /docs/jndi-resources-howto.html
-->
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<Service name="Catalina">
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
<!-- Use the LockOutRealm to prevent attempts to guess user passwords
via a brute-force attack -->
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
</Server>
【问题讨论】:
-
你是如何在tomcat中部署你的项目的?您确定通过检查日志来部署它们吗?
-
应用程序是否在 Tomcat 管理器中列出,它们是否已启动?主页是否正常工作 (
http://localhost:8080/)? -
@LuiggiMendoza 我正在通过 Idea 或管理器部署它。从日志中:“工件已成功部署”确认部署成功。
-
@Andreas 主页正在运行,我在管理器中列出的应用程序正在运行。
-
@2rec 是您的tomcat 的webapps 文件夹中的应用程序吗?你能发布你的 conf/server.xml 吗?
标签: java spring maven tomcat http-status-code-404