Spring Boot Jetty无法在AppEngine Flexible中启动Sping Boot 应用程序

vof42yt1  于 2023-11-17  发布在  Spring
关注(0)|答案(1)|浏览(150)

注意:这是一个交叉帖子,因为我不确定这是一个技术问题还是一个bug,所以可以在here中找到这个bug。
几周前,我写了一个原型,用于向我们的appengine项目添加一个灵活的环境服务,该项目主要是标准环境服务。该原型基于java快速入门示例“HelloworldSpringBoot”,并进行了一些微小的修改。
在我成功地使用原型之后,我为这项服务转移到了一组更生产的代码,开发了几个星期,并试图在1月12日部署,4天前。该应用程序拒绝启动,经过几次尝试将应用程序简化为一个单一的路由,我无法让应用程序启动。
我切换回原型代码,部署到代码工作的原始项目,并看到应用程序未启动的相同行为。
没有一个错误消息指向,所以我有一对夫妇,我会在这里列出,可能是罪魁祸首。
第一个是最明显的,但可能是一个通用的包罗万象:

  1. Exception in thread "main" java.lang.IllegalStateException: No Available Context
  2. at com.google.cloud.runtimes.jetty9.DeploymentCheck.lifeCycleStarted(DeploymentCheck.java:46)
  3. at org.eclipse.jetty.util.component.AbstractLifeCycle.setStarted(AbstractLifeCycle.java:179)
  4. at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
  5. at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1511)
  6. at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1438)
  7. at java.security.AccessController.doPrivileged(Native Method)
  8. at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1437)

字符串
接下来的事情发生在创业早期,但似乎是良性的:

  1. javax.servlet.ServletException: Not running on Jetty, JSR-356 support unavailable at org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer.onStartup(WebSocketServerContainerInitializer.java:193) at org.eclipse.jetty.plus.annotation.ContainerInitializer.callStartup(ContainerInitializer.java:140) at org.eclipse.jetty.annotations.ServletContainerInitializersStarter.doStart(ServletContainerInitializersStarter.java:63) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:329) at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1501) at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1463) at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:785) at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:261) at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:545) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at org.eclipse.jetty.deploy.bindings.StandardStarter.processBinding(StandardStarter.java:41) at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:188) at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:502) at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:150) at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAppProvider.java:180) at org.eclipse.jetty.deploy.providers.WebAppProvider.fileAdded(WebAppProvider.java:447) at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileAdded(ScanningAppProvider.java:64) at org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:610) at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:529) at org.eclipse.jetty.util.Scanner.scan(Scanner.java:392) at org.eclipse.jetty.util.Scanner.doStart(Scanner.java:313) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at org.eclipse.jetty.deploy.providers.ScanningAppProvider.doStart(ScanningAppProvider.java:150) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at org.eclipse.jetty.deploy.DeploymentManager.startAppProvider(DeploymentManager.java:564) at org.eclipse.jetty.deploy.DeploymentManager.doStart(DeploymentManager.java:239) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131) at org.eclipse.jetty.server.Server.start(Server.java:452) at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:113) at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113) at org.eclipse.jetty.server.Server.doStart(Server.java:419) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1511) at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1438) at java.security.AccessController.doPrivileged(Native Method) at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1437)


然后有这个家伙,发生在前一个:

  1. org.eclipse.jetty.webapp.WebAppContext: Failed startup of context o.e.j.w.WebAppContext@7e0b0338{/,file:///var/lib/jetty/webapps/root/,UNAVAILABLE}{/root.war}


另外,以下是相关文件:
app.yaml:

  1. runtime: java
  2. env: flex
  3. runtime_config: # Optional
  4. jdk: openjdk8
  5. service: service2
  6. handlers:
  7. - url: /.*
  8. script: this field is required, but ignored
  9. manual_scaling:
  10. instances: 1


build.gradle:

  1. buildscript { // Configuration for building
  2. ext {
  3. springBootVersion = '1.5.9.RELEASE'
  4. }
  5. repositories {
  6. jcenter() // Bintray's repository - a fast Maven Central mirror & more
  7. mavenCentral()
  8. maven { url 'https://repo.spring.io/libs-snapshot' }
  9. }
  10. dependencies {
  11. classpath 'com.google.cloud.tools:appengine-gradle-plugin:+'
  12. classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
  13. }
  14. }
  15. repositories { // repositories for JARs you access in your code
  16. maven {
  17. url 'https://maven-central.storage.googleapis.com' // Google's mirror of Maven Central
  18. }
  19. maven {
  20. url "http://repo.spring.io/libs-snapshot"
  21. }
  22. jcenter()
  23. mavenCentral()
  24. }
  25. apply plugin: 'java'
  26. apply plugin: 'war'
  27. apply plugin: 'com.google.cloud.tools.appengine'
  28. apply plugin: 'org.springframework.boot'
  29. dependencies {
  30. // Add your dependencies here.
  31. compile "org.springframework.boot:spring-boot-starter-web", { exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat' }
  32. compile (
  33. "org.springframework.boot:spring-boot-starter-actuator",
  34. "org.springframework.boot:spring-boot-starter-jetty"
  35. )
  36. testCompile (
  37. "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
  38. )
  39. }
  40. appengine {
  41. deploy { // deploy configuration
  42. stopPreviousVersion = true // default - stop the current version
  43. promote = true // default - & make this the current version
  44. }
  45. }
  46. group = 'com.example' // Generated output GroupId
  47. version = '1.0-SNAPSHOT' // Version in generated output
  48. sourceCompatibility = 1.8
  49. targetCompatibility = 1.8


HelloworldApplication.java:

  1. package com.example.java.gettingstarted;
  2. import org.springframework.boot.SpringApplication;
  3. import org.springframework.boot.autoconfigure.SpringBootApplication;
  4. import org.springframework.web.bind.annotation.RequestMapping;
  5. import org.springframework.web.bind.annotation.RestController;
  6. @SpringBootApplication
  7. @RestController
  8. public class HelloworldApplication {
  9. @RequestMapping("/service2/")
  10. public String home() {
  11. return "Helloooooooo Nurse!";
  12. }
  13. /**
  14. * (Optional) App Engine health check endpoint mapping.
  15. * @see <a href="https://cloud.google.com/appengine/docs/flexible/java/how-instances-are-managed#health_checking"></a>
  16. * If your app does not handle health checks, a HTTP 404 response is interpreted
  17. * as a successful reply.
  18. */
  19. @RequestMapping("/_ah/health")
  20. public String healthy() {
  21. // Message body required though ignored
  22. return "Still surviving.";
  23. }
  24. public static void main(String[] args) {
  25. SpringApplication.run(HelloworldApplication.class, args);
  26. }
  27. }


我也运行gcloud版本184.0.0

j5fpnvbx

j5fpnvbx1#

这个解决方案最终有点神奇,但SpringBoot documentation告诉我,一旦appengine标准文档为我指出了正确的方向。
请注意,只有在构建并部署war文件时才需要WebApplicationInitializer。如果您更喜欢运行嵌入式容器,则根本不需要它。
我们正在部署一个war,它在本地使用嵌入式容器运行。在按照提供的方式设置jetty并将神奇的SpringBootServletInitializer添加到根目录后,事情就开始工作了。我不知道为什么两周前不需要它,但现在肯定需要它。

  1. import org.springframework.boot.builder.SpringApplicationBuilder;
  2. import org.springframework.boot.web.support.SpringBootServletInitializer;
  3. public class ServletInitializer extends SpringBootServletInitializer {
  4. @Override
  5. protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
  6. System.out.println("ServletInitializer called.");
  7. return application.sources(HelloworldApplication.class);
  8. }
  9. }

字符串
把这个文件放在根目录下就可以了。
谢谢你的帮助

展开查看全部

相关问题