2

@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;

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

4

1 回答 1

1

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

于 2012-10-22T19:26:21.780 回答