[英]Glassfish-4 jersey REST application resource not found
我正在使用Glassfish 4,并且已经使用简单的REST Web服务创建了一个简单的Web应用程序。 一切工作正常,直到我尝试创建新的glassfish安装。 完成新安装后,我部署了war,并且成功部署了war,并且在glassfish日志上没有任何错误。 部署后,当我从管理控制台提供的URL启动Web应用程序时:
http://localhost:8080/MyRESTWebApp_war/
我收到状态404找不到错误...
这是我的web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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_3_1.xsd"
version="3.1">
<servlet>
<servlet-name>MyRESTWebApp</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>my.package.rest</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MyRESTWebApp</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
我还配置了带有@Path注释的扩展Application的类:
@ApplicationPath("/rest")
public class MyRESTWebAppApplication extends Application
{
@Override
public Set<Class<?>> getClasses()
{
return getResourceClasses();
}
private Set<Class<?>> getResourceClasses()
{
Set<Class<?>> resources = new HashSet<>();
resources.add(Example.class);
return resources;
}
}
我不记得我在以前的glassfish安装中做了什么配置,这非常令人沮丧...
当我尝试测试示例helloworld Rest服务时,我还会收到404错误:
http://localhost:8080/MyRESTWebApp_war/rest/helloworld
网址http:// localhost:8080 / MyRESTWebApp_war / rest / rest /呢?
您的rest api URL从/ rest / *开始,您的资源类url也从/ rest开始。
您不能仅使用http:// localhost:8080 / rest /访问它吗? 您的Example.class
什么样的?
更新
我认为您无法访问该URL的原因非常简单,您的服务已经很好地部署在http:// localhost:8080 / MyRESTWebApp_war / rest /上,并且您收到了404响应的事实是因为您没有在该路径上实现了GET方法。 尝试创建这样的资源:
@Path("/")
class RootResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello(){
return "Hello"
}
}
几条玻璃鱼重新启动后,我的其余服务按预期工作。
访问时,我仍然收到404错误:
http://localhost:8080/MyRESTWebApp_war/
但是,当我单击完整的RESTful服务链接时:
http://localhost:8080/MyRESTWebApp_war/rest/helloworld
我正在得到预期的回应...
我仍然没有弄清楚我做错了什么,这几乎花了我整整一天的时间...谢谢大家的时间和建议!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.