简体   繁体   English

将Spring Boot应用程序部署到AWS Beanstalk

[英]Deploying Spring Boot app to AWS beanstalk

I am trying since yesterday to deploy a spring boot in Tomcat on AWS Beanstalk and I always have this exception being raised : 从昨天开始,我一直在尝试在AWS Beanstalk上的Tomcat中部署Spring Boot,但始终会引发此异常:

    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'errorPageFilter': Initialization of bean failed;
      .....

       Caused by: java.lang.ClassCastException: org.springframework.boot.context.web.ErrorPageFilter cannot be cast to org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory
        at org.coursera.symptomserver.auth.config.OAuth2SecurityConfiguration$1.customize(OAuth2SecurityConfiguration.java:212)
        at org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizerBeanPostProcessor.postProcessBeforeInitialization(EmbeddedServletContainerCustomizerBeanPostProcessor.java:67)
        at org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizerBeanPostProcessor.postProcessBeforeInitialization(EmbeddedServletContainerCustomizerBeanPostProcessor.java:54)
 ...

In my local dev environment, I don't have this error. 在我本地的开发环境中,我没有这个错误。 In my local dev, I developped on Tomcat 7 with the '1.0.2.RELEASE' version. 在我的本地开发人员中,我使用'1.0.2.RELEASE'版本在Tomcat 7上进行了开发。

I created a war with that I deploy on Tomcat 7 instance in AWS Beanstalk and the error below always comes out. 我与之战,是在AWS Beanstalk的Tomcat 7实例上部署的,总是出现以下错误。 How can I fix this error? 如何解决此错误?

When you deploy a Spring Boot application to a standalone servlet container, it uses a special "embedded" servlet container, ErrorPageFilter , to handle application errors by forwarding requests to the configured error pages. 当您将Spring Boot应用程序部署到独立的servlet容器时,它使用特殊的“嵌入式” servlet容器ErrorPageFilter通过将请求转发到已配置的错误页面来处理应用程序错误。 The code in org.coursera.symptomserver.auth.config.OAuth2SecurityConfiguration$1 is incorrectly assuming that this class is a org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory which is resulting in a ClassCastException . org.coursera.symptomserver.auth.config.OAuth2SecurityConfiguration$1的代码错误地假定该类是org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory ,从而导致ClassCastException

The first thing to do is to make this code more robust by adding an instanceof check so that it only attempts the cast when it knows that it'll succeed. 首先要做的是通过添加一个instanceof check来使此代码更健壮,以便仅在知道它将成功的instanceof才尝试强制类型转换。 Secondly, as you're actually deploying to a standalone Tomcat instance, you'll need to apply this customisation to Tomcat by changing its server.xml or context.xml rather than doing it programatically. 其次,在实际部署到独立的Tomcat实例时,您需要通过更改Tomcat的server.xmlcontext.xml而不是以编程方式将其应用于Tomcat。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM