如何在Errai IOC中使用提供商?

时间:2012-10-22 10:26:28

标签: gwt guice errai

我遇到@IocProvider()问题,注释不起作用。 代码与https://docs.jboss.org/author/display/ERRAI/Container+Wiring

非常相似
public interface Test {
    String getGreeting();
}

@ApplicationScoped
public class TestImpl implements Test {
    public String getGreeting() {
        return "Hello:)";
    }
}

@IOCProvider
@Singleton
public class TestProvider implements Provider<Test> {
    @Override
    public Test get() {
        return new TestImpl();
    }
}

然后我想在我的广播服务(errai-bus)中使用DI。

@Service
public class BroadcastService implements MessageCallback {
    @Inject
    Test test;

    @Inject
    MessageBus bus;

    @Inject
    public BroadcastService(MessageBus bus) {
        this.bus = bus;
    }

    public void callback(Message message) {


        MessageBuilder.createMessage()
                .toSubject("BroadcastReceiver")
                .with("BroadcastText", test.getGreeting()).errorsHandledBy(new ErrorCallback() {
            @Override
            public boolean error(Message message, Throwable throwable) {
                return true;
            }
        }).sendNowWith(bus);
    }
}

我收到错误:

1) No implementation for com.gwtplatform.samples.basic.server.Test was bound.
  while locating com.gwtplatform.samples.basic.server.Test
    for field at com.gwtplatform.samples.basic.server.BroadcastService.test(BroadcastService.java:32)
  at org.jboss.errai.bus.server.service.ServiceProcessor$1.configure(ServiceProcessor.java:118)

如果我将代码更改为

@Inject
TestImpl test;

它有效,但我需要提供者。你有什么想法吗?

1 个答案:

答案 0 :(得分:1)

因为你试图在服务器端代码中使用@IOCProvider。 Errai IOC完全是客户端的。