- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 Grizzly 之上运行 Jersey 2.26-b09,并使用以下代码启动 Grizzly HTTP 服务器:
public void start() {
URI uri = UriBuilder.fromPath("").scheme("http").host("localhost").port(8084).path("/rest").build();
Map<String, String> params = new HashMap<>(16);
String applicationClassName = RestApplication.class.getName();
String applicationPackageName = RestApplication.class.getPackage().getName();
String productionPackageName = ProductionService.class.getPackage().getName();
params.put(ServletProperties.JAXRS_APPLICATION_CLASS, applicationClassName);
params.put(ServerProperties.PROVIDER_PACKAGES, productionPackageName + "," + applicationPackageName);
HttpServer server = GrizzlyWebContainerFactory.create(uri, params);
server.start();
}
RestApplication 类扩展了 Application,并具有 @ApplicationPath("/system") 注释。ProductionService 类是带有 @Path("/product") 注释的 REST 资源。
我可以看到 @ApplicationPath 中指定的路径被忽略:我的资源可以在/rest/product 访问,而不是在/rest/system/product 访问。
我尝试将 URI 更改为/rest/system 而不是/rest,但没有成功:
URI uri = UriBuilder.fromPath("").scheme("http").host("localhost").port(8084).path("/rest/system").build();
应用程序部署在根上下文/rest 中,而不是/rest/system 中。
我错过了什么?
当然,作为解决方法,我可以将资源路径从“/生产”更改为“/系统/生产”,但我想知道为什么应用程序路径被忽略。
最佳答案
我已将创建和初始化服务器的代码更改为:
public void start() {
URI uri = UriBuilder.fromPath("").scheme("http").host("localhost").port(8084).build();
Map<String, String> params = new HashMap<>(16);
String applicationPackageName = RestApplication.class.getPackage().getName();
String productionPackageName = ProductionService.class.getPackage().getName();
params.put(ServerProperties.PROVIDER_PACKAGES, productionPackageName + "," + applicationPackageName);
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(uri);
WebappContext context = new WebappContext("system", "/rest/system");
ServletRegistration registration = context.addServlet("jersey", ServletContainer.class);
registration.setInitParameters(params);
registration.addMapping("/*");
context.deploy(server);
server.start();
}
Web 应用程序上下文已创建,并在所需路径上提供资源。由于在此编程方法中未调用 servlet 容器初始值设定项,因此未设置 ServletProperties.JAXRS_APPLICATION_CLASS 属性。
我认为设置此属性可以完成工作,但事实并非如此。感谢@peeskillet 的提示。
关于java - Jersey +Grizzly - @ApplicationPath 被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45771768/
swagger-jaxrs 1.5.18 我在 @ApplicationPath("/docs") 处有一个应用程序,在其下有一个位于 @Path("/mydocs") 处的资源。因此,真正的端点是/
我正在尝试从 Visual Studio 代码以 Debug模式运行应用程序。当我单击调试时,出现以下错误: A JavaScript error occurred in the main proce
我需要获取我的 ASP.NET-MVC-5-Application 的 Base-/Application-Path。 我找到了两次获得它的机会,想知道哪个是更好的选择: UrlHelper.Cont
我一直在尝试在全局 asax 的 Application_Start 事件上获取我的项目的应用程序路径我可以在未路由的页面上使用 server.mappath 但是当我在路由页面上时我得到新的虚拟pa
我目前正在尝试设置我的第一个 Java-EE (JDK8) 应用程序,但无法覆盖上下文根以使用 @ApplicationPath 注释。正在使用的应用程序服务器是 Wildfly 16.0.0.Fin
我在 Grizzly 之上运行 Jersey 2.26-b09,并使用以下代码启动 Grizzly HTTP 服务器: public void start() { URI uri = UriB
在我的 razor View 中,我想将所有 jQuery 放入一个单独的 JS 文件中,然后使用 @Scripts.Render 在 View 上引用该文件。 在我看来,我有一个 jQuery 部分
在我的开发服务器上 HttpContext.Current.Request.ApplicationPath 正确返回路径,但在生产环境中它返回空。 为什么会这样? 我正在使用它来构建 URL,但现在在
环境 = JBoss 7.2.0.Final + RESTEasy 2.3.5.Final + Swagger 1.3.10 尝试设置一个没有 web.xml 的 WAR 并使用 Swagger。如果
根据JAXRS规范,@ApplicationPath可以用在接口(interface)上吗? import javax.ws.rs.ApplicationPath; @ApplicationPath(
我正在尝试在没有 web.xml 的情况下将基本的 jersey restful 服务部署到 Tomcat7: @WebServlet(loadOnStartup=1) @ApplicationP
有没有更编程的方式,相当于下面的配置: @ApplicationPath("api") public class MyResourceConfig extends ResourceConfig { ,
我正在寻找一种重写 url 的方法,以防 url 中的应用程序路径具有不同的大小写。由于应用程序路径可能因不同的部署而异,因此我需要动态访问它。有什么办法吗? 背景: 我正在将 cookie 的路径设
我正在从 Jboss 6.4/Java8 -> JBoss 7.2/Java11 转换应用程序,并且遇到错误,应用程序似乎忽略了我的端点注释并返回错误代码404. 您可以在日志中看到 Web 上下文的
有没有办法在一次调用中获取 HttpContext.Current.Request.Url.Host 和 HttpContext.Current.Request.ApplicationPath? 像“
我刚刚引导了一个 Intellij JAX-RS 项目,但在尝试运行时,我得到了样板代码提供的“/api/hello-world”的 404。 HelloServlet 在 Tomcat 10 上工作
使用这样的代码安全吗? Response.Cookies[cookieName].Path = Request.ApplicationPath + "/"; 我想知道所有极端情况,请... 最佳答案
我正在创建一个 mvc 应用程序,我将在子域下使用 http://myapp.mycompany.com 此子域指向应用程序子目录,但我的操作始终使用 applicationPath(子目录)生成,例
我想使用端点路径在 tomcat 上运行我的项目以下是我的两个 java 文件 这是我的应用类 package app; import javax.ws.rs.ApplicationPath;
我在项目中使用 Jersey 和 Spring。 'jersey-spring3' 用于它们之间的集成。我想让我的资源类更加灵活,并在 @Path 注释中使用属性,例如: @Path("${some.
我是一名优秀的程序员,十分优秀!