当前位置: 代码迷 >> java >> 如何避免“ServiceConfigException:不存在版本!” 使用 Cloud Endpoint Frameworks 实施 API 管理时出错?
  详细解决方案

如何避免“ServiceConfigException:不存在版本!” 使用 Cloud Endpoint Frameworks 实施 API 管理时出错?

热度:56   发布时间:2023-07-26 14:25:45.0

我在 Eclipse 中创建的一个新的基于 Maven 的 App Engine 标准项目中构建了一个测试 API。 添加 API 管理并部署到生产服务器后,我在端点门户上试用 API 时收到 500 响应。 仪表板中的错误日志显示以下异常:

endpoints.repackaged.com.google.api.config.ServiceConfigException: 
Failed to fetch default config version for service 'networking-1088.appspot.com'.
No versions exist!

我检查了类似的这样的问题,但我已经使用这个项目ID作为服务名称一致地的文件,并没有包括服务版本,并使用所有必要的样板代码的文档。

以下是我的文件中的相关片段:

pom.xml

<properties>
    <appengine.maven.plugin.version>1.3.2</appengine.maven.plugin.version>

    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>

    <maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>

    <endpoints.project.id>networking-1088</endpoints.project.id>
</properties>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.google.cloud</groupId>
            <artifactId>google-cloud-bom</artifactId>
            <version>0.80.0-alpha</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <!-- Compile/runtime dependencies -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>
        <version>1</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>javax.servlet.jsp-api</artifactId>
        <version>2.3.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>

    <dependency>
        <groupId>com.google.endpoints</groupId>
        <artifactId>endpoints-framework</artifactId>
        <version>2.2.1</version>
    </dependency>
    <!-- [START api_management] -->
    <dependency>
        <groupId>com.google.endpoints</groupId>
        <artifactId>endpoints-management-control-appengine-all</artifactId>
        <version>1.0.11</version>
    </dependency>
    <!-- [END api_management] -->
    <dependency>
        <groupId>com.googlecode.objectify</groupId>
        <artifactId>objectify</artifactId>
        <version>5.1.22</version>
    </dependency>
    <dependency>
        <groupId>com.google.appengine</groupId>
        <artifactId>appengine-api-1.0-sdk</artifactId>
        <version>1.9.71</version>
    </dependency>
</dependencies>

<build>
    <!-- for hot reload of the web application -->
    <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>versions-maven-plugin</artifactId>
            <version>2.3</version>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>display-dependency-updates</goal>
                        <goal>display-plugin-updates</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <webResources>
                    <resources>
                        <directory>${basedir}/src/main/webapp/WEB-INF</directory>
                        <filtering>true</filtering>
                        <targetPath>WEB-INF</targetPath>
                    </resources>
                </webResources>
            </configuration>
        </plugin>
        <plugin>
            <groupId>com.google.cloud.tools</groupId>
            <artifactId>appengine-maven-plugin</artifactId>
            <version>${appengine.maven.plugin.version}</version>
        </plugin>
        <!-- [START endpoints_plugin] -->
        <plugin>
            <groupId>com.google.cloud.tools</groupId>
            <artifactId>endpoints-framework-maven-plugin</artifactId>
            <version>1.0.2</version>
            <configuration>
                <!-- plugin configuration -->
                <hostname>${endpoints.project.id}.appspot.com</hostname>
            </configuration>
        </plugin>
        <!-- [END endpoints_plugin] -->
    </plugins>
</build>

网页.xml

<!-- Wrap the backend with Endpoints Frameworks v2. -->
<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>com.iitbaapune.app.RegistrantEndpoint</param-value>
    </init-param>
</servlet>

<!-- Route API method requests to the backend. -->
<servlet-mapping>
    <servlet-name>EndpointsServlet</servlet-name>
    <url-pattern>/_ah/api/*</url-pattern>
</servlet-mapping>

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<!-- [START api_management] -->
<!-- Add a filter that fetches the service config from service management. -->
<filter>
    <filter-name>endpoints-api-configuration</filter-name>
    <filter-class>com.google.api.control.ServiceManagementConfigFilter</filter-class>
</filter>

<!-- Add a filter that performs Endpoints logging and monitoring. -->
<filter>
    <filter-name>endpoints-api-controller</filter-name>
    <filter-class>com.google.api.control.extensions.appengine.GoogleAppEngineControlFilter</filter-class>
    <init-param>
        <param-name>endpoints.projectId</param-name>
        <param-value>${endpoints.project.id}</param-value>
    </init-param>
    <init-param>
        <param-name>endpoints.serviceName</param-name>
        <param-value>${endpoints.project.id}.appspot.com</param-value>
    </init-param>
</filter>

<filter-mapping>
    <filter-name>endpoints-api-configuration</filter-name>
    <servlet-name>EndpointsServlet</servlet-name>
</filter-mapping>

<filter-mapping>
    <filter-name>endpoints-api-controller</filter-name>
    <servlet-name>EndpointsServlet</servlet-name>
</filter-mapping>
<!-- [END api_management] -->

appengine-web.xml

  <!-- [START env_variables] -->
<env-variables>
    <env-var name="ENDPOINTS_SERVICE_NAME" value="networking-1088.appspot.com" />
</env-variables>
<!-- [END env_variables] -->

如何在保留 API 管理的同时摆脱此错误?

对于它的价值,我有同样的问题。 取消对 endpoints-api-configuration 过滤器的注释,使错误消失,但让我没有身份验证支持。

最后,在根据提供的示例重建整个项目时,我注意到GOOGLE_APPLICATION_CREDENTIALS是我的com.google.api.control.ConfigFilter doFilter: Rejecting this API request due to config loading error.

 <env-variables>
   <env-var name="ENDPOINTS_SERVICE_NAME" value="${endpoints.project.id}.appspot.com" />
   <env-var name="GOOGLE_APPLICATION_CREDENTIALS" value="WEB-INF/myproject-firebase-adminsdk-xyz.json" />
 </env-variables>

在我的情况下,省略GOOGLE_APPLICATION_CREDENTIALS错误消失......

  相关解决方案