迁移到端点框架版本2时获取NoSuchMethodException

时间:2018-07-23 11:52:31

标签: google-app-engine google-cloud-endpoints google-cloud-endpoints-v2

当我尝试将现有端点版本1.o代码迁移到端点框架版本2时,出现NoSuchMethod异常。

我在此处使用此网址中的指南

https://cloud.google.com/endpoints/docs/frameworks/java/migrating

但我一直收到此错误消息

java.lang.NoSuchMethodException: sampe-package-path.EndpointClassEndpoint.<init>()
    at java.lang.Class.getConstructor0(Class.java:3082)
    at java.lang.Class.newInstance(Class.java:412)
    at com.google.api.server.spi.EndpointsServlet.createService(EndpointsServlet.java:143)
    at com.google.api.server.spi.EndpointsServlet.createSystemService(EndpointsServlet.java:128)
    at com.google.api.server.spi.EndpointsServlet.init(EndpointsServlet.java:57)

我在迁移示例中使用了确切的web.xml

https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/appengine/endpoints-frameworks-v2/migration-example/src/main/webapp/WEB-INF/web.xml

我可能会缺少一些东西吗?

在上面的Endpoint类中,我只有一个这样的参数构造器

@Inject
public EndpointClassEndpoint(EndpointClassContext context) {
    this.context = context;
}

希望能帮助您解决此错误

按照@saiyr的要求添加完整的web.xml

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <listener>
        <listener-class>
            somethpath.bootstrap.CompanyOneGSCL
        </listener-class>
    </listener>

 <listener>
        <listener-class>
            somethpath.bootstrap.listeners.ObjectifyLoaderContextListener
        </listener-class>
    </listener>

    <!-- GUICE -->
    <filter>
        <filter-name>guiceFilter</filter-name>
        <filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>guiceFilter</filter-name>
        <url-pattern>/_ah/spi/*</url-pattern>
        <url-pattern>/*</url-pattern>
    </filter-mapping>


    <!-- ENDPOINTS -->
    <servlet>
        <servlet-name>EndpointsServlet</servlet-name>
        <servlet-class>com.google.api.server.spi.EndpointsServlet</servlet-class>
        <init-param>
            <param-name>services</param-name>
            <param-value>
                somethpath.endpoints.PraxoneV1API,
                somethpath.endpoints.EmpresasEndpoint,
                csomethpath.endpoints.AdministrationEndpoint,
                somethpath.endpoints.CentrosEndpoint,
                somethpath.endpoints.CargosEndpoint,
                somethpath.endpoints.TrabajadoresEndpoint,
                somethpath.endpoints.EvaluacionEndpoint,
                somethpath.endpoints.EpidemiologiaEndpoint,
                somethpath.endpoints.ActividadEndpoint,
                somethpath.endpoints.TrabajadoresOpenEndpoint,
                somethpath.endpoints.AsyncJobEndpoint
            </param-value>
        </init-param>
    </servlet>

    <servlet-mapping>
    <servlet-name>EndpointsServlet</servlet-name>
    <url-pattern>/_ah/api/*</url-pattern>
    </servlet-mapping>


    <!-- MonitorCompanyTask Servlet -->
    <servlet>
        <servlet-name>MonitorCompanyTask</servlet-name>
        <servlet-class>reducted-path.MonitorCompanyTask</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>MonitorCompanyTask</servlet-name>
        <url-pattern>/tasks/v1/monitor/company</url-pattern>
    </servlet-mapping>



    <!--servlet>
        <servlet-name>appstats</servlet-name>
        <servlet-class>com.google.appengine.tools.appstats.AppstatsServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>appstats</servlet-name>
        <url-pattern>/appstats/*</url-pattern>
    </servlet-mapping>

    <security-constraint>
        <web-resource-collection>
            <web-resource-name>appstats</web-resource-name>
            <url-pattern>/appstats/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>admin</role-name>
        </auth-constraint>
    </security-constraint -->

    <!-- All app must use HTTPS -->
    <security-constraint>
        <web-resource-collection>
            <web-resource-name>any</web-resource-name>
            <url-pattern>/*</url-pattern>
        </web-resource-collection>
        <user-data-constraint>
            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
        </user-data-constraint>
    </security-constraint>
</web-app>

当我做gradle依赖时,这就是我得到的

+--- com.google.endpoints:endpoints-framework:2.0.8
|    +--- javax.servlet:servlet-api:2.5
|    +--- com.google.guava:guava:19.0 -> 20.0
|    +--- com.fasterxml.jackson.core:jackson-annotations:2.6.4 -> 2.9.0
|    +--- com.fasterxml.jackson.core:jackson-core:2.6.4 -> 2.9.6
|    +--- com.fasterxml.jackson.core:jackson-databind:2.6.4 -> 2.9.6
|    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.9.0
|    |    \--- com.fasterxml.jackson.core:jackson-core:2.9.6
|    +--- com.google.appengine:appengine-api-1.0-sdk:1.9.49 -> 1.9.64
|    +--- com.google.http-client:google-http-client-jackson2:1.21.0 -> 1.23.0
|    |    +--- com.google.http-client:google-http-client:1.23.0
|    |    |    +--- com.google.code.findbugs:jsr305:1.3.9 -> 3.0.1
|    |    |    \--- org.apache.httpcomponents:httpclient:4.0.1 -> 4.5.2
|    |    |         +--- org.apache.httpcomponents:httpcore:4.4.4
|    |    |         +--- commons-logging:commons-logging:1.2
|    |    |         \--- commons-codec:commons-codec:1.9 -> 1.10
|    |    \--- com.fasterxml.jackson.core:jackson-core:2.1.3 -> 2.9.6
|    +--- com.google.api-client:google-api-client:1.21.0 -> 1.23.0
|    |    +--- com.google.oauth-client:google-oauth-client:1.23.0
|    |    |    +--- com.google.http-client:google-http-client:1.23.0 (*)
|    |    |    \--- com.google.code.findbugs:jsr305:1.3.9 -> 3.0.1
|    |    +--- com.google.http-client:google-http-client-jackson2:1.23.0 (*)
|    |    \--- com.google.guava:guava-jdk5:17.0
|    +--- com.google.api-client:google-api-client-appengine:1.21.0 -> 1.23.0
|    |    +--- com.google.oauth-client:google-oauth-client-appengine:1.23.0
|    |    |    +--- com.google.http-client:google-http-client-appengine:1.23.0
|    |    |    |    \--- com.google.http-client:google-http-client:1.23.0 (*)
|    |    |    +--- com.google.oauth-client:google-oauth-client:1.23.0 (*)
|    |    |    \--- com.google.oauth-client:google-oauth-client-servlet:1.23.0
|    |    |         +--- com.google.oauth-client:google-oauth-client:1.23.0 (*)
|    |    |         +--- com.google.http-client:google-http-client-jdo:1.23.0
|    |    |         |    +--- com.google.http-client:google-http-client:1.23.0 (*)
|    |    |         |    \--- javax.jdo:jdo2-api:2.3-eb
|    |    |         |         \--- javax.transaction:transaction-api:1.1
|    |    |         \--- javax.jdo:jdo2-api:2.3-eb (*)
|    |    +--- com.google.api-client:google-api-client:1.23.0 (*)
|    |    +--- com.google.api-client:google-api-client-servlet:1.23.0
|    |    |    +--- com.google.oauth-client:google-oauth-client-servlet:1.23.0 (*)
|    |    |    +--- com.google.api-client:google-api-client:1.23.0 (*)
|    |    |    +--- javax.servlet:servlet-api:2.5
|    |    |    \--- javax.jdo:jdo2-api:2.3-eb (*)
|    |    \--- com.google.http-client:google-http-client-appengine:1.23.0 (*)
|    +--- com.google.code.findbugs:jsr305:3.0.1
|    +--- io.swagger:swagger-models:1.5.9
|    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.4.5 -> 2.9.0
|    |    +--- org.slf4j:slf4j-api:1.6.3 -> 1.7.21
|    |    \--- io.swagger:swagger-annotations:1.5.9
|    +--- io.swagger:swagger-core:1.5.9
|    |    +--- org.apache.commons:commons-lang3:3.2.1
|    |    +--- org.slf4j:slf4j-api:1.6.3 -> 1.7.21
|    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.4.5 -> 2.9.0
|    |    +--- com.fasterxml.jackson.core:jackson-databind:2.4.5 -> 2.9.6 (*)
|    |    +--- com.fasterxml.jackson.datatype:jackson-datatype-joda:2.4.5
|    |    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.4.0 -> 2.9.0
|    |    |    +--- com.fasterxml.jackson.core:jackson-core:2.4.5 -> 2.9.6
|    |    |    +--- com.fasterxml.jackson.core:jackson-databind:2.4.5 -> 2.9.6 (*)
|    |    |    \--- joda-time:joda-time:2.2 -> 2.9.4
|    |    +--- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.4.5
|    |    |    +--- com.fasterxml.jackson.core:jackson-core:2.4.5 -> 2.9.6
|    |    |    \--- org.yaml:snakeyaml:1.12
|    |    +--- io.swagger:swagger-models:1.5.9 (*)
|    |    +--- com.google.guava:guava:18.0 -> 20.0
|    |    \--- javax.validation:validation-api:1.1.0.Final
|    \--- org.slf4j:slf4j-nop:1.7.21
|         \--- org.slf4j:slf4j-api:1.7.21

我可以看到com.google.appengine:appengine-api-1.0-sdk:1.9.49-> 1.9.64以及其他看起来像端点1依赖项的文件,在这里可以吗?

1 个答案:

答案 0 :(得分:0)

由于尝试使用Guice,因此需要像migration guide中那样配置端点。请注意,除非您使用API​​管理,否则Guice模块中的某些行是不相关的。调用configureEndpoints的最后一行是最重要的。然后将该模块添加到您的Guice配置中。