我无法使用Google guice获取谷歌 Cloud endpoints . 从 endpoints 库中可用的类看来,这应该是可能的,但我不清楚如何连接它,我看不到任何文档 .
显然was a solution,但从那时起API似乎发生了变化 .
我尝试扩展com.google.api.server.spi.guice.SystemServiceModule,覆盖configure()和getServiceClasses(),并实现GuiceServletContextListener .
调用GuiceServletContextListeneris上的getInjector()方法,从而调用SystemServiceModule上的configure()方法,但从不调用“getServiceClasses()方法 . 调用服务时,服务类没有注入任何依赖项 .
有人知道如何正确连线吗?
2 回答
使用guice endpoints 的关键是使servlet映射正确 . 尝试
添加Guice监听器并过滤到web.xml
对于Endpoints Framework v2,您可以扩展EndpointsModule .
将此依赖项添加到项目中:
并像这样扩展模块:
完整示例:
https://github.com/GoogleCloudPlatform/java-docs-samples/tree/master/appengine/endpoints-frameworks-v2/guice-example
随附文件:https://cloud.google.com/endpoints/docs/frameworks/java/using-guice