我想和泽西岛一起做一个REST服务,我完全迷失了我在标题中提到的参数。当我部署我的东西时,它不起作用。我打不到控制器。
我想要实现的是,我可以部署多个EAR文件,每个EAR文件包含一个WAR文件,这是REST端点。
例如:
其中applicationrestservice1和2是完全不同的应用程序,放在分开的ear/war文件中。
就我而言:
那么,问题是:以下参数是如何在url中表示的?
<servlet-mapping><url-pattern><webModule><contextRoot>服务器为WildFly 10,泽西版本为2.25.1。还需要什么信息?
我已经搜索这个信息有一段时间了,但发现的东西提出了更多的问题而不是给出答案。
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>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
<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>@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();
}
}发布于 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资源路径}
每段末端的斜线将合并成一个斜杠。
https://stackoverflow.com/questions/44106481
复制相似问题