When I deploy my Web Application to Wildfly 22.0.0, I can't seem to find the path for my Rest resource:
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
<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
@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
@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. 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. So I removed the @ApplicationPath anotation in RestApplication.java .
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
<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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.