简体   繁体   English

如何使用Guice注入Google App Engine数据存储区?

[英]How to inject Google App Engine datastore with Guice?

I'm trying to inject Google App Engine's datastore via Guice into my service: 我正试图通过Guice将Google App Engine的数据存储注入我的服务中:

public class FooServiceImpl implements FooService {

    private final DatastoreService datastoreService;

    @Inject
    public FooServiceImpl (DatastoreService datastoreService) {
        this.datastoreService = datastoreService;
    }
}

But when I try to run it, I get the following error: 但是当我尝试运行它时,我收到以下错误:

No implementation for com.google.appengine.api.datastore.DatastoreService was bound. 没有绑定com.google.appengine.api.datastore.DatastoreService的实现。

Add @Provides method to your module: @Provides方法添加到您的模块:

@Provides
DatastoreService provideDatastoreService(){
    return DatastoreServiceFactory.getDatastoreService();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM