简体   繁体   English

Google App Engine标准环境 - 未找到控制器方法 - Spring Boot应用程序

[英]Google App Engine Standard env - not found controller method - Spring Boot app

I was trying to deploy Spring Boot application on Google App Engine (standard environment). 我试图在Google App Engine(标准环境)上部署Spring Boot应用程序。 At first I cloned example app from this nice tutorial https://springframework.guru/spring-boot-web-application-part-4-spring-mvc/ 起初我从这个很好的教程中克隆了示例应用程序https://springframework.guru/spring-boot-web-application-part-4-spring-mvc/

For example I called http://localhost:8080/products and template with data was displayed. 例如,我调用了http:// localhost:8080 / products ,并显示了带有数据的模板。

So everything ran without problems, I was able to call all controller methods locally. 所以一切都没有问题,我能够在本地调用所有控制器方法。 Then I decided as experiment to deploy it on GAE. 然后我决定将其部署在GAE上进行实验。 I adjusted pom.xml according to instructions from here https://github.com/GoogleCloudPlatform/getting-started-java/tree/master/appengine-standard-java8/springboot-appengine-standard 我根据这里的说明调整了pom.xml https://github.com/GoogleCloudPlatform/getting-started-java/tree/master/appengine-standard-java8/springboot-appengine-standard

It means I excluded Tomcat dependency, changed packaging from jar to war, created appengine-web.xml file etc. As next step, I created GAE project in GAE console and copied APP ID into appengine-web.xml. 这意味着我排除了Tomcat依赖关系,将包装从jar更改为war,创建了appengine-web.xml文件等。下一步,我在GAE控制台中创建了GAE项目,并将APP ID复制到appengine-web.xml中。 Then I ran mvn clean package and war was created in target folder. 然后我运行了mvn clean package并在目标文件夹中创建了war。 Finally I started with GAE deployment and it also went smoothly without errors. 最后,我开始使用GAE部署,它也顺利进行,没有错误。

My app is now deployed on this URL https://20180109t135551-dot-oe-gae-test.appspot.com/ 我的应用程序现已部署在此URL https://20180109t135551-dot-oe-gae-test.appspot.com/

If you try it, you will see Hello World in browser. 如果您尝试它,您将在浏览器中看到Hello World。 But if I try to call /products controller method like this https://20180109t135551-dot-oe-gae-test.appspot.com/products I get "not found" error. 但是,如果我尝试调用这样的产品控制器方法https://20180109t135551-dot-oe-gae-test.appspot.com/products,我会收到“未找到”错误。

Can you give me advice on which URL should I call my controller methods? 你能给我一些关于我应该调用我的控制器方法的URL的建议吗? Did I forget to implement something like web.xml servlet mapping? 我是否忘记实现web.xml servlet映射之类的东西? Or is it some specific Spring Boot - Google App Engine problem? 或者是一些特定的Spring Boot - Google App Engine问题?

I will be grateful for any hint. 我会感激任何提示。

Thank you all in advance 谢谢大家

Following this steps translates into the following for the code : 按照此步骤转换为以下代码

  1. In pom.xml, change <packaging>jar</packaging> to <packaging>war</packaging> 在pom.xml中,将<packaging>jar</packaging>更改为<packaging>war</packaging>

  2. In the package guru.springframework add this class: 在包guru.springframework添加这个类:

Code: 码:

package guru.springframework;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringBootWebApplication {

public static void main(String[] args) {
        SpringApplication.run(SpringBootWebApplication.class, args);
    }
}    
  1. Remove Tomcat Starter: 删除Tomcat Starter:

Find this dependency in the POM: 在POM中找到此依赖项:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

And add these lines: 并添加以下行:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
  1. Exclude Jetty dependencies and include the Servlet API dependency: 排除Jetty依赖项并包含Servlet API依赖项:

    <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency>

  2. Add the App Engine Standard plugin: 添加App Engine标准插件:

     <plugin> <groupId>com.google.cloud.tools</groupId> <artifactId>appengine-maven-plugin</artifactId> <version>1.3.1</version> </plugin> 
    1. Add a file called appengine-web.xml in src/webapp/WEB-INF with these contents: src/webapp/WEB-INF添加一个名为appengine-web.xml的文件,其中包含以下内容:

    <appengine-web-app xmlns="http://appengine.google.com/ns/1.0"> <threadsafe>true</threadsafe> <runtime>java8</runtime> </system-properties> </appengine-web-app>

    1. Exclude JUL to SLF4J Bridge by locating this dependency in the pom: 通过在pom中找到此依赖项,将JUL排除到SLF4J Bridge:

    <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency>

and modifying it this way: 并以这种方式修改它:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>jul-to-slf4j</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
  1. Avoiding out of memory errors: 避免内存不足错误:

In src/main/resources add a logging.properties file with: src/main/resources添加一个logging.properties文件:

.level = INFO

and inside src/main/webapp/WEB-INF/appengine-web.xml paste this: src/main/webapp/WEB-INF/appengine-web.xml粘贴这个:

<system-properties>
    <property name="java.util.logging.config.file" value="WEB-INF/classes/logging.properties" />
</system-properties>

EDIT: 编辑:

For steps 3 and 7 you can also go to the project explorer (in case you're using Eclipse) and navigate to Libraries -> Maven dependencies and select each library individually ( jul-to-slf4j-1.7.25 and spring-boot-starter-tomcat-1.5.3.RELEASE in my case). 对于步骤37您还可以转到项目资源管理器(如果您正在使用Eclipse)并导航到库 - > Maven依赖项并单独选择每个库( jul-to-slf4j-1.7.25spring-boot-starter-tomcat-1.5.3.RELEASE在我的例子中, spring-boot-starter-tomcat-1.5.3.RELEASE )。 Right click on each library and go to Maven -> Exclude Maven artifact ... And click Ok . 右键单击每个库并转到Maven - > Exclude Maven artifact ...然后单击Ok This will have the same effect on the POM as editing. 这将对POM产生与编辑相同的效果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring Boot可以在Google标准应用引擎上运行吗? - Can spring boot run on google standard app engine? 不稳定的 Google Cloud Engine - 标准环境 - 延迟(Spring Boot 应用程序) - Erratic Google Cloud Engine - Standard Environment - Latency (Spring Boot App) 通过春季启动在Google App Engine中进行Cron作业 - Cron job in Google app engine with spring boot Spring 在 Google Cloud App Engine 上启动托管 - Spring Boot hosting on Google Cloud App Engine 在Google App Engine标准版上运行Spring Boot Application时发生javax.el.E​​xpressionFactory错误 - javax.el.ExpressionFactory Error when running Spring Boot Application on Google App Engine Standard 如何在适用于Google App Engine(标准)的Spring Boot应用程序上使用调试器 - How can I use the debugger on a Spring Boot application for the Google App Engine (standard) 部署到 Google App Engine 的 Spring Boot (Gradle) 应用返回 404 Not Found - Spring Boot (Gradle) app deployed to Google App Engine returns 404 Not Found Google App Engine上的Spring Boot应用程序:无法找到主类 - Spring Boot app on Google App Engine: unable to find main class 在 Google App Engine 中部署 Spring boot gradle 应用 - Deploy Spring boot gradle app in Google App Engine Google App Engine 上 Spring Boot 应用程序的 Maven 配置文件 - Maven Profile for Spring Boot App on Google App Engine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM