jersey - Embedded Jetty + 2 Jersey Servlet:无法同时加载
问题描述
请帮忙!
我在配置 Embedded Jetty 以在 2 个类中运行 2 个 Jersey Servlet 时遇到问题,包条目。它从 Eclipse 运行,但是一旦导出为可运行的 jar 文件,我得到 ERROR: 500,第二次运行。它是 Maven 项目,我用来创建可运行 jar 的工具是<groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId>
,
而服务器点配置如下:
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
context.setContextPath("/");
HttpConfiguration https = new HttpConfiguration();
https.addCustomizer(new SecureRequestCustomizer());
ServerConnector connector = new ServerConnector(jettyServer);
connector.setPort(10001);
jettyServer.setConnectors(new Connector[] { connector });
jettyServer.setHandler(context);
ServletHolder jerseyServletEntry = context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class,
"/entry/*");
jerseyServletEntry.setInitOrder(0);
jerseyServletEntry.setInitParameter("jersey.config.server.provider.classnames",
EntryPoint.class.getCanonicalName());
EntryPoint.logger.info("Server is starting up... ");
ServletHolder jerseyServletNoEntry = context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class,
"/noentry/*");
jerseyServletNoEntry.setInitOrder(1);
jerseyServletNoEntry.setInitParameter("jersey.config.server.provider.classnames",
NoEntryPoint.class.getCanonicalName());
NoEntryPoint.logger.info("Server is starting up... ");
我遇到的邮递员错误:
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1" />
<title>Error 500 </title>
</head>
<body>
<h2>HTTP ERROR: 500</h2>
<p>Problem accessing /entry/input//7858/768434. Reason:
<pre> Request failed.</pre>
</p>
<hr /><i><small>Powered by Jetty://</small></i>
</body>
提醒:它在 Eclipse 中运行良好,在控制台中使用 java -jar 命令运行时没有列出错误。
解决方案
我通过更改 ServerPoint 中的配置解决了这个问题,如下所示:
代替:
ServletHolder jerseyServletEntry = context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class,
"/entry/*");
jerseyServletEntry.setInitOrder(0);
jerseyServletEntry.setInitParameter("jersey.config.server.provider.classnames",
EntryPoint.class.getCanonicalName());
EntryPoint.logger.info("Server is starting up... ");
ServletHolder jerseyServletNoEntry = context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class,
"/noentry/*");
jerseyServletNoEntry.setInitOrder(1);
jerseyServletNoEntry.setInitParameter("jersey.config.server.provider.classnames",
NoEntryPoint.class.getCanonicalName());
NoEntryPoint.logger.info("Server is starting up... ");
我写:
ServletHolder jerseyServletEntry = context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class,
"/api/*");
jerseyServletEntry.setInitOrder(0);
jerseyServletEntry.setInitParameter("jersey.config.server.provider.classnames",
"entry.EntryPoint, entry.NoEntryPoint"); //upload both Jersey servlets
ServerPoint.logger.info("Server is starting up... ");
但是现在,我发现 JCE 无法验证提供的 BC。尝试了这个解决方案,但没有成功:bouncycastle 错误“JCE 无法验证提供者 BC”和“jar-with-dependencies” 在 Eclipse 中工作正常,但在导出时不能。任何想法?
推荐阅读
- c# - WPF/XAML - 绑定到 TextBox PreviewTextInput 事件
- scala - 如何在 Spark 中创建一个空的 dataFrame
- python - Python程序在网站上查找活动端口?
- javascript - 如何通过文本查找和替换列表项?
- c++ - 覆盖柯南存储目录
- spring - 在密码更改openldap spring中获取BadCredentialsException
- git - 在 Intellij 中 HEAD 和 HEAD 上游的版本控制日志中过滤分支
- javascript - 使用输入数字更新显示的段落数 - HTML Javascript
- java - Apache shiro 到 httpsession 管理的变化
- c++ - 构造函数中的 C++ 2D 数据数组 - 何时初始化和删除?