使用guice注入jetty spring servlet(或更改它以便我可以注入它)

时间:2015-05-08 15:46:43

标签: java spring servlets jersey jetty

我克隆了servlet: https://github.com/eHarmony/vw-webservice。我想从我的码头代码启动这个servlet。我正在使用guice将类添加到jetty。看起来我需要移动applicationContext,因此它可以作为jar而不是war。我没有码头或弹簧的经验。我很想听听你对它的看法。

GuiceConfig.java

public class GuiceConfig extends GuiceServletContextListener
{
    @Override
    protected Injector getInjector()
    {
        return Guice.createInjector(new JerseyServletModule() {
            @Override
            protected void configureServlets() {    
                bind(ClassThatProcessRequest.class);

                bind(InjecteeInterface.class).to(Injectee.class);
                serve("/*").with(GuiceContainer.class);
            }
        });
    }
}

和main.java

public class Main {

    public static void main(String[] args) throws Exception {
        Server server = new Server(8080);
        ServletContextHandler root = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);

        root.addEventListener(new GuiceConfig());
        root.addFilter(GuiceFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
        root.addServlet(EmptyServlet.class, "/*");

        server.start();
    }
}

当我启动服务器时,我得到了

com.google.inject.CreationException: Guice creation errors:

No implementation for com.eharmony.matching.vw.webservice.core.exampleprocessor.ExampleProcessorFactory was bound.

这里是applicationContext.xml和web.xml https://github.com/eHarmony/vw-webservice/blob/master/vw-webservice-jersey/src/main/webapp/WEB-INF/applicationContext.xml

https://github.com/eHarmony/vw-webservice/blob/master/vw-webservice-jersey/src/main/webapp/WEB-INF/web.xml

0 个答案:

没有答案