如何将属性文件加载到嵌入式jetty?

时间:2015-10-09 06:54:03

标签: java jetty embedded-jetty

我正在运行嵌入式jetty服务器。我想在启动之前注入系统属性,如数据库uri,名称,传递给服务器,我该怎么办呢?属性位于类路径中不存在的.ini文件中。 服务器如下所示:

public static void main(String[] args) throws Exception {

        Server server = new Server();
        ServerConnector connector = new ServerConnector(server);
        connector.setPort(8080);
        server.addConnector(connector);

        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
        context.setContextPath("/");

        ServletHolder servletHolder = new ServletHolder(ServletContainer.class);
        servletHolder.setInitOrder(0);
        servletHolder.setInitParameter("jersey.config.server.provider.packages", "com/server/");
        context.addServlet(servletHolder, "/*");

        context.addFilter(RequestFilter.class, "/*", EnumSet.of(DispatcherType.INCLUDE,
                DispatcherType.REQUEST, DispatcherType.ASYNC, DispatcherType.ERROR,
                DispatcherType.FORWARD));

        GzipHandler gzipHandler = new GzipHandler();
        gzipHandler.setExcludedMimeTypes("application/javascript", "application/json");

        FilterHolder corsFilterHolder = new FilterHolder(CrossOriginFilter.class);
        corsFilterHolder.setInitParameter("allowedOrigins", "*");
        corsFilterHolder.setInitParameter("allowedMethods", "OPTIONS, HEAD, GET, POST, PUT, DELETE, PATCH");
        corsFilterHolder.setInitParameter("allowedHeaders", "X-IGP");
        context.addFilter(corsFilterHolder, "/*", EnumSet.of(DispatcherType.REQUEST));

        server.setHandler(gzipHandler);
        server.setHandler(context);

        try {
            server.start();
            logger.debug("Server started");
            logger.debug(server);
            server.join();
        } catch (Throwable t) {
            logger.error(System.err);
        } finally {
            server.destroy();
        }
    }

0 个答案:

没有答案