Dropwizard与大气和guice集成问题

时间:2014-11-21 15:12:07

标签: integration guice atmosphere dropwizard

我正在尝试将dropwizard与氛围和guice结合在一起,我遵循了一些互联网链接,例如:

我已按照本指南将dropwizard与氛围集成:link

我的atmosphere-guice

项目中有依赖项

最后,我在我的环境设置中添加了一个用于集成注入器

的监听器
 @Override
    public void run(final MyConfig configuration, final Environment environment) throws Exception {

// ...
        environment.servlets().addServletListeners(new GuiceServletContextListener() {
            @Override
            protected Injector getInjector() {
                return injector;
            }
        });
// ...
}

我还整合了一些代码,如dropwizard-guice所示:

// ...
final GuiceContainer container = new GuiceContainer();
modules.add(new GuiceJerseyContainerModule(container));
// ...

最后,我正在添加一个带有以下声明的AbstractModule,因为documentation from Atmosphere描述了

@Provides
AtmosphereResourceFactory provideAtmosphereResourceFactory(AtmosphereGuiceServlet atmosphereGuiceServlet) {
     return atmosphereGuiceServlet.framework().atmosphereFactory();
}

@Provides
BroadcasterFactory provideBroadcasterFactory(AtmosphereGuiceServlet atmosphereGuiceServlet) {
     return atmosphereGuiceServlet.framework().getBroadcasterFactory();
}

现在我正在尝试在我的一个资源上添加AtmosphereResourceFactory,我想使用它并通过

向特定用户发送内容
@Path("/")
public class IndexResource {

    @Inject
    private AtmosphereResourceFactory resourceFactory;


    @GET
    @Path("/{user}")
    public String sayHello(@PathParam("user") String user){
       AtmosphereResource resource = resourceFactory.find(user); // not found
       resourse.write("Some message");
    }
}

我的问题是这个特定的实例与AtmosphereResource不同,资源数量为零,而我同时通过一个简单的websocket客户端连接资源。

有没有人遇到过类似的问题?如何使用不同的AtmosphereResourceFactory实例?在我的应用程序中,这不应该是单身人士吗?

谢谢,如果需要其他信息,请告诉我

很抱歉长篇说明

0 个答案:

没有答案