У меня проблема с развертыванием простого веб-приложения helloworld restful на Tomcat 9 в java 8 в IntelliJ. Единственное, что я получаю, - это индекс. jsp страница под http://localhost:8080/Rozpro2_war_exploded/
По адресам ../Rozpro2_war_exploded/rest | ../Rozpro2_war_exploded/rest/hello | ../rest | ../rest/hello | ../Rozpro2/hello | ../hello
Я получаю HTTP-статус 404 - Не найдено, как в браузере, так и в Почтальоне
Интернет. xml:
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>services</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
Класс HelloWrold:
package services;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("hello")
public class HelloWorld {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String sayHello(){
return "Hello,I am text!";
}
@POST
@Produces(MediaType.TEXT_XML)
public String sayXMLHello() {
return "<?xml version=\"1.0\"?>" + "<hello> Hello,I am xml!" + "</hello>";
}
@GET
@Produces(MediaType.TEXT_HTML)
public String sayHtmlHello() {
return "<html> " + "<title>" + "Hello Jersey" + "</title>"
+ "<body><h1>" + "Hello,I am html!" + "</body></h1>" + "</html> ";
}
}
Index. jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
Hey
</body>
</html>
pom. xml, поскольку я импортирую материал с помощью Maven :
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>services</groupId>
<artifactId>Rozpro2</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.29</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>2.29</version>
</dependency>
</dependencies>
</project>
Запуск конфигурации: запуск конфигурации
Когда я запускаю сервер Tomcat, я получаю журналы:
[2020-03-15 11:55:24,049] Artifact Rozpro2:war exploded: Artifact is being deployed, please wait...
15-Mar-2020 11:55:25.539 INFO [RMI TCP Connection(2)-127.0.0.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.
[2020-03-15 11:55:27,512] Artifact Rozpro2:war exploded: Artifact is deployed successfully
[2020-03-15 11:55:27,512] Artifact Rozpro2:war exploded: Deploy took 3,463 milliseconds
web. xml находится в WEB-INF, и я вижу службы в out / artifacts / Rozpro2_war_exploded / WEB-INF / services с HelloWorld. java внутри. Кто-нибудь знает, почему я не могу получить ответ от определенного URL?