gpt4 book ai didi

java - Google 云端点和依赖项注入(inject)

转载 作者:行者123 更新时间:2023-11-30 08:11:27 25 4
gpt4 key购买 nike

当我在端点类中注入(inject)服务时遇到问题。

[INFO] java.lang.RuntimeException: Cannot instantiate service class: fr.cloudintra.endpoints.endpoint.VacationRequestEndPoint
[INFO] at com.google.api.server.spi.SystemServiceServlet.createService(SystemServiceServlet.java:242)
[INFO] at com.google.api.server.spi.SystemServiceServlet.registerService(SystemServiceServlet.java:229)
[INFO] at com.google.api.server.spi.SystemServiceServlet.createSystemService(SystemServiceServlet.java:222)
[INFO] at com.google.api.server.spi.SystemServiceServlet.createSystemService(SystemServiceServlet.java:184)
[INFO] at com.google.api.server.spi.SystemServiceServlet.init(SystemServiceServlet.java:106)
[INFO] at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:440)
[INFO] at org.mortbay.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:339)
[INFO] at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
[INFO] at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
[INFO] at com.googlecode.objectify.cache.AsyncCacheFilter.doFilter(AsyncCacheFilter.java:58)
[INFO] at com.googlecode.objectify.ObjectifyFilter.doFilter(ObjectifyFilter.java:48)
[INFO] at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
[INFO] at com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
[INFO] at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
[INFO] at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:127)
[INFO] at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
[INFO] at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
[INFO] at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
[INFO] at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63)
[INFO] at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
[INFO] at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
[INFO] at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
[INFO] at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)
[INFO] at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
[INFO] at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectRequest(DevAppServerModulesFilter.java:366)
[INFO] at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectModuleRequest(DevAppServerModulesFilter.java:349)
[INFO] at com.google.appengine.tools.development.DevAppServerModulesFilter.doFilter(DevAppServerModulesFilter.java:116)
[INFO] at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
[INFO] at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
[INFO] at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
[INFO] at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
[INFO] at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
[INFO] at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
[INFO] at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:98)
[INFO] at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
[INFO] at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:503)
[INFO] at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
[INFO] at org.mortbay.jetty.Server.handle(Server.java:326)
[INFO] at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
[INFO] at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:938)
[INFO] at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)
[INFO] at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
[INFO] at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
[INFO] at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
[INFO] at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
[INFO] Caused by: java.lang.InstantiationException: fr.cloudintra.endpoints.endpoint.VacationRequestEndPoint.<init>()

Guice 用于管理依赖注入(inject)。

端点类:

public class VacationRequestEndPoint {

private VacationRequestGateway vacationRequestGateway;

@Inject
public VacationRequestEndPoint(VacationRequestGateway vacationRequestGateway) {
this.vacationRequestGateway = vacationRequestGateway;
}

@ApiMethod(name = "list", httpMethod = ApiMethod.HttpMethod.GET, path = "list")
public Collection<VacationRequest> getVacationRequests() {
return vacationRequestGateway.findVacationRequests();
}
}

网关:

public class VacationRequestGateway {
{
ObjectifyService.register(VacationRequest.class);
}

public Collection<VacationRequest> findVacationRequests() {
return ofy().load().type(VacationRequest.class).list();
}
}

以及终点测试类(通过):

@RunWith(MockitoJUnitRunner.class)
public class VacationRequestEndPointTest {

@Mock
private VacationRequestGateway mockGateway;

@InjectMocks
private VacationRequestEndPoint endPoint;

@Test
public void testGetVacationRequests() throws Exception {
endPoint.getVacationRequests();

verify(mockGateway).findVacationRequests();
}
}

并且不知道如何在我的端点上注入(inject)网关。我是否需要覆盖端点的初始化方式?

谢谢。

最佳答案

正如 konqi 猜测的那样,问题在于 com.google.api.server.spi.SystemServiceServlet.createService() 正在调用 java.lang.Class#createInstance() VacationRequestEndPointVacationRequestEndPoint 上的 code> 没有无参数构造函数。

我不知道您为什么期望 Guice 实例化 VacationRequestEndPoint,但我怀疑您向 Google Cloud 基础架构注册 VacationRequestEndPoint 时出现配置错误.

关于java - Google 云端点和依赖项注入(inject),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30336776/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com