spring - Google cloud App engine Spring deploy error
问题描述
Im trying to deploy a springboot rest api to google cloud's app engine, following this recent tutorial: https://medium.com/@smccartney09/deploy-a-spring-boot-api-to-gcp-app-engine-722198bab4d4and
However i'm getting this error:
org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
The app runs normally in localhost, from what I can see trying to debug, on localhost springboot launches a tomcat web server, and it doesn't in the logs form google app run deployment. Does this mean I have to use google's web server instead of tomcat? i'm really lost as to what i'm doing wrong right now.
POM xml:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.1</version>
<relativePath/>
</parent>
<groupId>com.owl</groupId>
<artifactId>owl-server</artifactId>
<version>0.0</version>
<name>owl-server</name>
<description>owl backend server</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.4</version>
</dependency>
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>2.3.9</version>
</dependency>
<dependency>
<groupId>io.vavr</groupId>
<artifactId>vavr</artifactId>
<version>0.10.3</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.4</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-sql-mysql</artifactId>
<version>1.2.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
main:
@SpringBootApplication
@EnableCaching
public class OwlServerApplication {
public static void main(String[] args) {
SpringApplication.run(OwlServerApplication.class, args);
}
Ok, so after a lot of reading i think it might be because google app engine doesnt support tomcat as a webserver, and instead only supports jetty? so i tried the following:
added to pom xml:
<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>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
but this does nothing, same exact error. I then tried to add jetty as well, which runs locally great as a jetty web server, but gives the same error on app engine. So we know the error is due to google app engine not supporting tomcat or jetty, but what do i use now? Anyone have any idea on whats going wrong?
解决方案
所以经过大量调试,这里的问题出在spring security。如果你有一个扩展 WebSecurityConfigurerAdapter 的类,spring 会自动尝试将它应用到嵌入式 tomcat web 服务器。谷歌应用引擎不支持它,这打破了它。只需删除课程,该应用程序即可运行。
推荐阅读
- mysql - 如何从 2 个表中选择最近的日期时间
- android - cocos2d 如果在应用启动时手机被锁定,会导致应用放弃所有触摸和音量控制事件
- openssl - 从 JRuby 向不支持 JRuby 的 SSL 密码的服务发送 HTTPS 请求
- javascript - Ajax 调用返回 HTTP 302
- asp.net-mvc - IdentityServer4 和 Web API 在同一个项目中
- java - Java - 查找最长的子字符串 - LinkedList 问题
- c# - C# UWP 读取串行数据抛出异常
- reactjs - 如何从反应页面重定向到表达页面
- javascript - 累积 GPA 计算器
- javascript - Mongo ObjectID 不相等