我尝试用ApacheTomcat对服务器进行处理以创建类似tutorialspoint的API
我将.war文件创建到/webapps
中,所以我有/webapps/UserManagement.war
当我尝试启动服务器并打开http://localhost:8080
没问题,但使用http://localhost:8080/UserManagement
或http://localhost:8080/UserManagement/rest/UserService/users
时,它将显示404错误。
Tomcat如何工作?我阅读了一些以前发布在此处的子项目,并再次阅读了教程,但我没有发现做错了什么
/ webapps和/ webapps / UserManagement中的内容
[root@localhost webapps]# ls ; ls -R UserManagement
docs examples host-manager manager ROOT UserManagement UserManagement.war
UserManagement:
META-INF UserManagement.war WEB-INF
UserManagement/META-INF:
MANIFEST.MF war-tracker
UserManagement/WEB-INF:
classes lib
UserManagement/WEB-INF/classes:
com
UserManagement/WEB-INF/classes/com:
tutorialspoint
UserManagement/WEB-INF/classes/com/tutorialspoint:
User.class UserDao.class UserService.class web.xml
UserManagement/WEB-INF/lib:
aopalliance-repackaged-2.5.0-b05.jar hk2-utils-2.5.0-b05.jar javax.inject-2.5.0-b05.jar jaxb-api-2.2.7.jar jersey-container-servlet-core.jar jersey-media-jaxb.jar osgi-resource-locator-1.0.1.jar
hk2-api-2.5.0-b05.jar javassist-3.20.0-GA.jar javax.servlet-api-3.0.1.jar jersey-client.jar jersey-container-servlet.jar jersey-server.jar persistence-api-1.0.jar
hk2-locator-2.5.0-b05.jar javax.annotation-api-1.2.jar javax.ws.rs-api-2.0.1.jar jersey-common.jar jersey-guava-2.24.jar org.osgi.core-4.2.0.jar validation-api-1.1.0.Final.jar
[root@localhost webapps]#
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3c.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"
id="WebApp_ID" version="3.0">
<display-name>USER MANAGEMENT</display-name>
<servlet>
<servlet-name>Jerset Restful App</servlet-name>
<servlet-class> org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.package</param-name>
<param-value>com.tutorialspoint</param-value>
</init-param>
</servlet>
<servlet-mapping>
<serlet-name>Jersey RESTful Application</serlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
日志
18-Nov-2016 09:53:24.974 INFOS [main] org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/9.0.0.M13
18-Nov-2016 09:53:25.066 INFOS [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Nov 3 2016 20:59:41 UTC
18-Nov-2016 09:53:25.067 INFOS [main] org.apache.catalina.startup.VersionLoggerListener.log Server number: 9.0.0.0
18-Nov-2016 09:53:25.067 INFOS [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Linux
18-Nov-2016 09:53:25.067 INFOS [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 3.10.0-327.36.3.el7.x86_64
18-Nov-2016 09:53:25.067 INFOS [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64
18-Nov-2016 09:53:25.067 INFOS [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: /usr/java/jdk1.8.0_111/jre
18-Nov-2016 09:53:25.067 INFOS [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_111-b14
18-Nov-2016 09:53:25.067 INFOS [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
18-Nov-2016 09:53:25.067 INFOS [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: /usr/local/apache-tomcat-9.0.0.M13
18-Nov-2016 09:53:25.068 INFOS [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: /usr/local/apache-tomcat-9.0.0.M13
18-Nov-2016 09:53:25.068 INFOS [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/local/apache-tomcat-9.0.0.M13/conf/logging.properties
18-Nov-2016 09:53:25.068 INFOS [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
18-Nov-2016 09:53:25.068 INFOS [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
18-Nov-2016 09:53:25.068 INFOS [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
18-Nov-2016 09:53:25.068 INFOS [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/local/apache-tomcat-9.0.0.M13
18-Nov-2016 09:53:25.068 INFOS [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/local/apache-tomcat-9.0.0.M13
18-Nov-2016 09:53:25.069 INFOS [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/apache-tomcat-9.0.0.M13/temp
18-Nov-2016 09:53:25.069 INFOS [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.\
path: /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
18-Nov-2016 09:53:25.718 INFOS [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
18-Nov-2016 09:53:25.820 INFOS [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
18-Nov-2016 09:53:25.838 INFOS [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
18-Nov-2016 09:53:25.840 INFOS [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
18-Nov-2016 09:53:25.840 INFOS [main] org.apache.catalina.startup.Catalina.load Initialization processed in 2273 ms
18-Nov-2016 09:53:25.913 INFOS [main] org.apache.catalina.core.StandardService.startInternal Démarrage du service Catalina
18-Nov-2016 09:53:25.913 INFOS [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/9.0.0.M13
18-Nov-2016 09:53:26.000 INFOS [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Déploiement de l'archive /usr/local/apache-tomcat-9.0.0.M13/webapps/UserManagement.war de l'application web
18-Nov-2016 09:53:27.375 INFOS [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.
18-Nov-2016 09:53:27.594 INFOS [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive /usr/local/apache-tomcat-9.0.0.M13/webapps/UserManagement.war has finished in 1 578 ms
18-Nov-2016 09:53:27.595 INFOS [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Déploiement du répertoire /usr/local/apache-tomcat-9.0.0.M13/webapps/ROOT de l'application web
18-Nov-2016 09:53:27.635 INFOS [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/apache-tomcat-9.0.0.M13/webapps/ROOT has finished in 40 ms
18-Nov-2016 09:53:27.636 INFOS [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Déploiement du répertoire /usr/local/apache-tomcat-9.0.0.M13/webapps/docs de l'application web
18-Nov-2016 09:53:27.679 INFOS [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/apache-tomcat-9.0.0.M13/webapps/docs has finished in 44 ms
18-Nov-2016 09:53:27.679 INFOS [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Déploiement du répertoire /usr/local/apache-tomcat-9.0.0.M13/webapps/examples de l'application web
18-Nov-2016 09:53:28.169 INFOS [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/apache-tomcat-9.0.0.M13/webapps/examples has finished in 490 ms
18-Nov-2016 09:53:28.170 INFOS [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Déploiement du répertoire /usr/local/apache-tomcat-9.0.0.M13/webapps/host-manager de l'application web
18-Nov-2016 09:53:28.360 INFOS [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/apache-tomcat-9.0.0.M13/webapps/host-manager has finished in 190 ms
18-Nov-2016 09:53:28.361 INFOS [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Déploiement du répertoire /usr/local/apache-tomcat-9.0.0.M13/webapps/manager de l'application web
18-Nov-2016 09:53:28.429 INFOS [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/apache-tomcat-9.0.0.M13/webapps/manager has finished in 68 ms
18-Nov-2016 09:53:28.434 INFOS [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler [http-nio-8080]
18-Nov-2016 09:53:28.439 INFOS [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler [ajp-nio-8009]
18-Nov-2016 09:53:28.439 INFOS [main] org.apache.catalina.startup.Catalina.start Server startup in 2599 ms
18-Nov-2016 10:00:59.030 INFOS [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.startup.HostConfig.undeploy Repli (undeploy) de l'application web ayant pour chemin de contexte /UserManagement
18-Nov-2016 10:00:59.080 INFOS [localhost-startStop-2] org.apache.catalina.startup.HostConfig.deployWAR Déploiement de l'archive /usr/local/apache-tomcat-9.0.0.M13/webapps/UserManagement.war de l'application web
18-Nov-2016 10:00:59.624 INFOS [localhost-startStop-2] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive /usr/local/apache-tomcat-9.0.0.M13/webapps/UserManagement.war has finished in 544 ms
最佳答案
我刚刚在网站上看到了该项目。它正在开发一个简单的RESTful Web服务,并且不包含默认的index.jsp或index.html文件。因此,当您尝试访问http://localhost:8080/UserManagement
时出现404错误是可以的。
要测试您的应用程序,您必须按照本教程中的说明在Web浏览器中运行url http://localhost:8080/UserManagement/rest/UserService/users
。