java - 如何配置 Spring 应用程序以在应用程序引擎上运行?
问题描述
这是一个将在 Google App 引擎上运行的 Spring Boot 服务器。但是它给了我一个例外:
Uncaught exception from servlet
java.lang.RuntimeException: javax.servlet.ServletException: Not running on Jetty, JSR-356 support unavailable
这是我的 pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.4</version>
<relativePath />
</parent>
<groupId>com.google.appengine.demos</groupId>
<artifactId>springboot-appengine-standard</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>springboot-appengine-standard</name>
<description>Demo project for Spring Boot</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<spring-cloud.version>2020.0.2</spring-cloud.version>
</properties>
<dependencies>
<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>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>2.4.0</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
据我所知,由于spring-jetty启动器和tomcat的排除,它在码头上运行。我在 web.xml 中映射了 servlet。因此,根据谷歌自己的文档和其他一些在线教程,这不应该工作没有合乎逻辑的理由。但是,一旦提出休息请求,而不是部署,它就会部署并运行,但是当提出请求时,它会给出我之前显示的异常。
我在@SpringBootStarter 中也有这个
@SpringBootApplication
public class HelloAppEngine extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(HelloAppEngine.class);
}
public static void main(String[] args) {
SpringApplication.run(HelloAppEngine.class, args);
}
}
解决方案
推荐阅读
- python - 我不能直接使用“pip install”
- testng - 处理错误:testng.selenium.endpoint 必须是配置的系统属性
- swift - 在排序异步任务和单独执行时遇到问题
- python - 恢复和暂停 python 脚本(电视节目)
- tmux - 不是编辑器命令:TmuxNavigateLeft
- tcp - 如何使用跟踪路由发出 TCP SYN 请求
- clojure - 如何简化 Compojure 路由?
- sql - 在三个不同条件下加入同一张表
- list - 如何从列表中删除“项目列表”?
- javascript - 为什么 vue-cookies 在一个视图中工作,而不是另一个?