gpt4 book ai didi

java - 404 错误 : Resource not available jersey tomcat

转载 作者:行者123 更新时间:2023-11-28 23:35:16 25 4
gpt4 key购买 nike

我正在尝试实现简单的“Hello Jersey”程序。但它给了我

404 error: Resource not available

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>MessageProcessorMyTest</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Jersey MessageProcessor Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.example.wordcount</param-value>
</init-param>
<init-param>
<param-name>unit:WidgetPU</param-name>
<param-value>persistence/widget</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey MessageProcessor Application</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>

消息端.java:

package com.example.wordcount;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;


public class MessageEnd {

@GET
@Produces(MediaType.TEXT_PLAIN)
@Path("/send")

public String sayHello(){
return "Hello Jersey";
}
}

我使用的是jersey 2.11版本我的上下文根:消息当我指向

http://localhost:8080/message/

index.html 正在显示

但是,当我试图引导

http://localhost:8080/message/rest/send

404错误来了。

我在 webapp>WEB-INF>lib 目录中包含了以下 Jersey 文件: enter image description here

请指导我。

最佳答案

@Aparna Savant - I am able to "Hello Jersey" when I move @Path("/send") above class declaration. – Aparna Savant Aug 11 '14 at 19:10

非常感谢您写这篇文章。我浪费了将近 20 个小时来修复我的 API。

下面是我为修复代码所做的工作。

之前

@RestController
@Path("/api")
public class AuxdboAPIResouce {

之后

@Path("/api")
@RestController
public class AuxdboAPIResouce {

关于java - 404 错误 : Resource not available jersey tomcat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25250025/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com