简体   繁体   中英

How to inject Google App Engine datastore with Guice?

I'm trying to inject Google App Engine's datastore via Guice into my service:

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.

Add @Provides method to your module:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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