[英]Could not find path for REST resource (Wildfly 22.0.0 deployment)
When I deploy my Web Application to Wildfly 22.0.0, I can't seem to find the path for my Rest resource:当我将 Web 应用程序部署到 Wildfly 22.0.0 时,我似乎找不到 Rest 资源的路径:
Could not find resource for full path: http://127.0.0.1:8080/CourseManagementApplication/rest/api/assignments/list
I'm not sure what I'm doing wrong.我不确定我做错了什么。
web.xml web.xml
<servlet>
<servlet-name>RestApplication</servlet-name>
<servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>impl.rest.application.RestApplication</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>RestApplication</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
RestApplication.java RestApplication.java
@ApplicationPath("/api")
public class RestApplication extends Application {
@Override
public Set<Class<?>> getClasses() {
final Set<Class<?>> classes = new HashSet<>();
classes.add(AssignmentResource.class);
return classes;
}
}
AssignmentResource.java分配资源.java
@Path("/assignments")
public class AssignmentResource {
@GET
@Path("/list")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public Response getAssignments() {
return ........
}
}
I thought the resource would be accessible through the URI [Root]/rest/api/assignments/list.我认为可以通过 URI [Root]/rest/api/assignments/list 访问该资源。 I can't understand why this path doesn't work.
我不明白为什么这条路行不通。
There were two problems in this code:这段代码有两个问题:
1- As mentioned in the comment above, I shouldn't have used servlet-mapping and @ApplicationPath simultaneously. 1- 正如上面评论中提到的,我不应该同时使用 servlet-mapping 和 @ApplicationPath。 So I removed the @ApplicationPath anotation in RestApplication.java .
所以我删除了RestApplication.java中的@ApplicationPath注释。
2- I wasn't aware that in order to use a url pattern different from /*
, you should not only define it in the server-mapping
but it is also necessary to add the context-param
to the web.xml , like this 2-我不知道,要使用url模式与
/*
不同,您不仅应该在server-mapping
中定义它,而且还必须将context-param
添加到Z2567A5EC97AC9705EB7AC2C9884013E840F.98840FER tister -Param中
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/rest</param-value>
</context-param>
So the endpoint becomes correctly available in http://127.0.0.1:8080/CourseManagementApplication/rest/assignments/list因此端点在http://127.0.0.1:8080/CourseManagementApplication/rest/assignments/list中正确可用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.