简体   繁体   English

找不到 REST 资源的路径(Wildfly 22.0.0 部署)

[英]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.

相关问题 WildFly找不到完整路径的资源(没有XML,使用命令行部署) - WildFly Could not find resource for full path (no XML, using commandline deployment) Wildfly 10 + Rest Easy网络服务。 获取找不到完整路径错误的资源 - Wildfly 10 + Rest Easy web service. Getting Could not find resource for full path error Wildfly War部署获取资源文件的路径 - Wildfly war deployment get path to resource file javax.ws.rs.NotFoundException:无法使用 RESTEasy 和 Wildfly 8.1.0.Final 找到完整路径的资源 - javax.ws.rs.NotFoundException: Could not find resource for full path with RESTEasy and Wildfly 8.1.0.Final RESTEASY003210:找不到完整路径错误的资源 - RESTEASY003210: Could not find resource for full path error 带有WildFly的JavaEE:找不到Rest资源-为什么? - JavaEE with WildFly: Rest Resource not found - why? javax.ws.rs.NotFoundException:找不到完整路径的资源 - javax.ws.rs.NotFoundException: Could not find resource for full path RESTEASY003210:找不到完整路径的资源:Tomcat - RESTEASY003210: Could not find resource for full path : Tomcat REST中Wildfly中2个不同模块的相同路径 - same Path with REST for 2 Different Modules in Wildfly 在 Wildfly WFLYJCA0046 / IJ020066 上部署资源适配器 - Deployment of Resource Adapter on Wildfly WFLYJCA0046 / IJ020066
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM