首页 > 解决方案 > 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 命令运行时没有列出错误。

标签: jerseyjetty

解决方案


我通过更改 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 中工作正常,但在导出时不能。任何想法?


推荐阅读