在GCP部署GAE SpringBoot应用失败:Jetty JSR-356支持不可用错误
Hey, let's tackle this Jetty/JSR-356 error you're hitting when deploying your Spring Boot app to GAE. I've seen this pop up a few times, and it almost always boils down to dependency conflicts or misconfigured container settings with GAE's built-in Jetty. Here's how to fix it step by step:
1. Exclude Spring Boot's Default Tomcat Dependency
GAE Standard Environment uses Jetty as its underlying servlet container, but Spring Boot's spring-boot-starter-web defaults to Tomcat. This mismatch causes the conflict. You need to exclude Tomcat from your dependencies:
For Maven:
<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>
For Gradle:
implementation('org.springframework.boot:spring-boot-starter-web') { exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat' }
2. Add Jetty Starter Dependency
Replace the excluded Tomcat starter with Spring Boot's Jetty starter to align with GAE's environment:
For Maven:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jetty</artifactId> </dependency>
For Gradle:
implementation 'org.springframework.boot:spring-boot-starter-jetty'
3. Disable WebSocket Auto-Configuration (If Not Using WebSockets)
The error specifically mentions JSR-356 (the WebSocket API specification). If your app doesn't use WebSockets, you can disable Spring Boot's WebSocket auto-configuration to avoid triggering this initialization issue:
Add the exclude attribute to your main application class:
@SpringBootApplication(exclude = {WebSocketAutoConfiguration.class}) public class YourApplication { public static void main(String[] args) { SpringApplication.run(YourApplication.class, args); } }
4. Verify Your app.yaml Configuration
Make sure your app.yaml uses the correct runtime and doesn't override container settings. For example:
runtime: java17 instance_class: F1 handlers: - url: /.* script: auto
GAE will handle the Jetty container setup automatically—don't try to configure a custom container here.
Bonus: Check Dependency Versions
Ensure your Spring Boot version is compatible with the GAE Java runtime you're using. Stick to stable Spring Boot releases paired with supported Java versions (like 17) for the smoothest experience.
If you're still stuck after these steps, double-check for any other servlet container-related dependencies in your build files that might be conflicting with GAE's Jetty.
内容的提问来源于stack exchange,提问作者Ankit S

