我遵循了教程,但該專案不起作用。當我在 tomcat 中部署戰爭并訪問地址 http://localhost:8080/queroquero/rest/vendedor/get 我有 404 狀態,但如果我訪問 http://localhost:8080/queroquero/ 我得到一個“你好世界”。
@ApplicationPath("rest")
public class Main extends Application{ }
---------------------------------------------
@Path("vendedor")
public class VendedorResource {
@GET
@Path("get")
@Produces(MediaType.APPLICATION_JSON)
public Response get() {
String texto = new String("It's working!!!");
return Response.ok(texto).build();
}
}
我的 POM.xml 依賴項:
<dependencies>
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
<version>8.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.3</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.7</version>
</dependency>
</dependencies>
我的 web.xml:
<web-app>
<display-name>Archetype Created Web Application</display-name>
<!-- Auto scan REST service -->
</web-app>
我已經花了幾個小時,找不到什么是錯的或遺漏的。
uj5u.com熱心網友回復:
可能你需要改進你的@Path 定義?:據我所知你應該把:
@Path("/rest")
@Path("/venderdor")
@Path("/get")
uj5u.com熱心網友回復:
伙計們,問題是由 maven 匯入產生的沖突。至于尋找兼容性的庫的變化,我得到了結果。主要更改是更改 JAX 的 Jakarta 實作以實作 Jersey。如果有人想知道我是如何做到的,只需查看 github 中的完整代碼(Rest code)。不幸的是,我沒有時間去發現什么是雅加達實作的正確版本,哪些是匹配的。在這里分享一下pom.xml的依賴:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<!-- use the following artifactId if you don't need servlet 2.x compatibility -->
<!-- artifactId>jersey-container-servlet</artifactId -->
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.27</version>
</dependency>
</dependencies>
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/365923.html
