Google App Engine Standard env - 未找到控制器方法 - Spring Boot应用程序 [英] Google App Engine Standard env - not found controller method - Spring Boot app
问题描述
我试图在Google App Engine上部署Spring Boot应用程序(标准环境)。起初,我从这个不错的教程克隆了示例应用程序 https:/ /springframework.guru/spring-boot-web-application-part-4-spring-mvc/
例如,我将 http:// localhost:8080 / products ,并显示包含数据的模板。
所以一切都没有问题,我可以在本地调用所有控制器方法。然后,我决定将它作为实验部署在GAE上。我根据这里的指示调整了pom.xml https://github.com/GoogleCloudPlatform/getting-started-java/tree/master/appengine-standard-java8/springboot-appengine-standard
这意味着我排除了Tomcat依赖性,将jar包更改为war,创建了appengine-web.xml文件等。下一步,我在GAE控制台中创建了GAE项目,并将APP ID复制到appengine-web.xml中。然后我运行了mvn clean package并在目标文件夹中创建了war。
我的应用程序现在部署在此URL https://20180109t135551-dot-oe-gae-test.appspot.com/
如果您尝试它,您将在浏览器中看到Hello World。但是,如果我尝试调用/产品控制器方法,请按照以下方法 https:// 20180109t135551- dot-oe-gae-test.appspot.com/products 我收到未找到错误。
你能否给我建议调用我的控制器方法?我忘了实现类似web.xml servlet映射的东西吗?或者是一些特定的Spring Boot - Google App Engine问题?
我会很感激任何提示。
提前感谢大家
-
在pom.xml中,将
< packaging> jar< / packaging>
更改为
在包$
guru.springframework
代码:
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 );
- 删除Tomcat Starter:
在POM中查找此依赖项:
<依赖项>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-web< / artifactId>
< /依赖关系>
然后添加以下几行:
< dependency>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-web< / artifactId>
<排除项>
<排除>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-tomcat< / artifactId>
< /排除>
< /排除>
< /依赖关系>
-
排除Jetty依赖关系并包含Servlet API依赖关系:
< dependency>
< groupId> javax.servlet< / groupId>
< artifactId> javax.servlet-api< / artifactId>
< version> 3.1.0< / version>
< scope>提供< / scope>
< / dependency> -
添加App Engine标准插件:
< plugin>
< groupId> com.google.cloud.tools< / groupId>
< artifactId> appengine-maven-plugin< / artifactId>
< version> 1.3.1< / version>
< / plugin>
- 添加名为
中的 - 添加名为
- SLF4J Bridge通过在pom中定位这个依赖关系:
src / webapp / WEB-INF
< appengine-web-app xmlns =http://appengine.google.com/ns/1.0>
< threadsafe> true< / threadsafe>
< runtime> java8< / runtime>
< / system-properties>
< dependency>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-data-jpa< / artifactId>
< / dependency>
/ p>
< dependency>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-data-jpa< / artifactId>
<排除项>
<排除>
< groupId> org.slf4j< / groupId>
< artifactId> jul-to-slf4j< / artifactId>
< /排除>
< /排除>
< /依赖关系>
- 避免内存不足错误:
在 src / main / resources
中添加一个logging.properties文件:
.level = INFO
和内部 src / main / webapp / WEB-INF / appengine-web.xml
粘贴:
<系统-性状>
< property name =java.util.logging.config.filevalue =WEB-INF / classes / logging.properties/>
< / system-properties>
编辑:
对于步骤 3
和 7
,你也可以进入项目浏览器(如果你使用Eclipse )并导航到库 - > Maven依赖关系并单独选择每个库( jul-to-slf4j-1.7.25
和 spring-boot-starter-tomcat-1.5.3.RELEASE
在我的情况)。右键单击每个库,然后转到 Maven - >排除Maven工件 ...,然后单击确定。这将对编辑中的POM产生相同的效果。
I was trying to deploy Spring Boot application on Google App Engine (standard environment). At first I cloned example app from this nice tutorial 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.
So everything ran without problems, I was able to call all controller methods locally. Then I decided as experiment to deploy it on 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
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. Then I ran mvn clean package and war was created in target folder. Finally I started with GAE deployment and it also went smoothly without errors.
My app is now deployed on this URL https://20180109t135551-dot-oe-gae-test.appspot.com/
If you try it, you will see Hello World in browser. 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.
Can you give me advice on which URL should I call my controller methods? Did I forget to implement something like web.xml servlet mapping? Or is it some specific Spring Boot - Google App Engine problem?
I will be grateful for any hint.
Thank you all in advance
Following this steps translates into the following for the code:
In pom.xml, change
<packaging>jar</packaging>
to<packaging>war</packaging>
In the package
guru.springframework
add this class:
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);
}
}
- Remove Tomcat Starter:
Find this dependency in the 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>
Exclude Jetty dependencies and include the Servlet API dependency:
<dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency>
Add the App Engine Standard plugin:
<plugin> <groupId>com.google.cloud.tools</groupId> <artifactId>appengine-maven-plugin</artifactId> <version>1.3.1</version> </plugin>
- Add a file called
appengine-web.xml
insrc/webapp/WEB-INF
with these contents:
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0"> <threadsafe>true</threadsafe> <runtime>java8</runtime> </system-properties> </appengine-web-app>
- Exclude JUL to SLF4J Bridge by locating this dependency in the pom:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency>
- Add a file called
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>
- Avoiding out of memory errors:
In src/main/resources
add a logging.properties file with:
.level = INFO
and inside src/main/webapp/WEB-INF/appengine-web.xml
paste this:
<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). Right click on each library and go to Maven -> Exclude Maven artifact... And click Ok. This will have the same effect on the POM as editing.
这篇关于Google App Engine Standard env - 未找到控制器方法 - Spring Boot应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!