如何在泽西2.15中启用HK2 TopicDistributionService?

时间:2015-01-16 14:56:29

标签: java jersey jersey-2.0 event-bus hk2

我在尝试在球衣中启用Hk2 Events时遇到问题。

ResourceConfig:

import org.glassfish.hk2.utilities.TopicDistributionModule;

public class Application extends ResourceConfig {
    public Application() throws IOException {
        super(Application.class);
        register(TopicDistributionModule.class);
    }
}

资源:

@Path("/")
public class MainResource {
    @Inject
    private Topic<MyClass> myClassTopic;

    @GET
    @Produces(MediaType.TEXT_HTML)
    public String index() {
        return "index";
    }
}

我收到错误:

java.lang.IllegalStateException: There is no implementation of the TopicDistributionService to distribute the message
  at org.jvnet.hk2.internal.TopicImpl.publish(TopicImpl.java:79) ~[hk2-locator-2.3.0.jar:?]
  at ... MainResource.index(MainResource.java:21) ~[classes/:?]
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_20]

1 个答案:

答案 0 :(得分:0)

TopicDistributionModuleAbstractBinder,根据我的理解,应该将其注册为实例,而不是按类。此

register(new TopicDistributionModule());

应该摆脱异常,因为它注册了默认的TopicDistributionService。从那里,它只是确保你有一个&#34;生活&#34;发布事件/消息时的订阅者