首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >web.xml,servlet-mapping.url-模式和maven-ear-plugin contextRoot param是如何连接的?

web.xml,servlet-mapping.url-模式和maven-ear-plugin contextRoot param是如何连接的?
EN

Stack Overflow用户
提问于 2017-05-22 07:00:11
回答 1查看 1.1K关注 0票数 0

我想和泽西岛一起做一个REST服务,我完全迷失了我在标题中提到的参数。当我部署我的东西时,它不起作用。我打不到控制器。

我想要实现的是,我可以部署多个EAR文件,每个EAR文件包含一个WAR文件,这是REST端点。

例如:

  • http://localhost/applicationrestservice1/restapi/Module/getAllModule
  • http://localhost/applicationrestservice2/restapi/Other/getStuff

其中applicationrestservice1和2是完全不同的应用程序,放在分开的ear/war文件中。

就我而言:

  • ApplicationService1是放置在Application1.ear文件中的war文件,负责通过http://localhost/applicationrestservice1/ url提供REST服务。
  • ApplicationService2是一个放置在Application2.ear文件中的war文件,负责通过http://localhost/applicationrestservice2/ url提供REST服务。

那么,问题是:以下参数是如何在url中表示的?

  • web.xml - <servlet-mapping><url-pattern>
  • maven-ear-plugin - <webModule><contextRoot>
  • 放置在类上的@Path

服务器为WildFly 10,泽西版本为2.25.1。还需要什么信息?

我已经搜索这个信息有一段时间了,但发现的东西提出了更多的问题而不是给出答案。

web.xml

代码语言:javascript
复制
<?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>Digital Library - Metadata Service</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Digital Library - Metadata Service</servlet-name>
        <url-pattern>/restapi/*</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
</web-app>

pom.xml

代码语言:javascript
复制
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-ear-plugin</artifactId>
    <version>2.10.1</version>
        <configuration>
            <modules>
                <webModule>
                    <groupId>${project.groupId}</groupId>
                    <artifactId>RESTApi</artifactId>
                    <contextRoot>/</contextRoot>
                </webModule>
            </modules>
        </configuration>
</plugin>
代码语言:javascript
复制
@Path("/Module")
public class ModuleEndpoint implements ModuleEndpointInterface {

    @Override
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    @Path("/getAllModules")
    public Response getAllModules() {

        return Response.status(200)
                .entity("getAllModules")
                .type(MediaType.APPLICATION_JSON)
                .build();
    }
}
EN

回答 1

Stack Overflow用户

发布于 2022-01-21 21:47:51

这里的一些信息

例如,如果要部署响应URI路径模板http://example.com/myContextRoot/jerseybeans/{name1}/{name2}/的资源,必须将WAR部署到响应对http://example.com/myContextRoot URI的请求的Java服务器,然后使用以下@Path注释来修饰资源: @Path("/{name1}/{name2}/")公共类SomeResource {.} 在本例中,在web.xml中指定的泽西助手servlet的URL模式是默认的: 我的泽西豆资源\/泽西豆子/* 可以在URI路径模板中多次使用变量名称。

在实验上,在weblogic+maven+web.xml场景中,这向我证实了工作模式是:

http://myserver{webModule contextRoot}{web.xml servlet模式}{web.xml资源路径}

每段末端的斜线将合并成一个斜杠。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44106481

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档