I am trying since yesterday to deploy a spring boot in Tomcat on AWS Beanstalk and I always have this exception being raised :
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.
I created a war with that I deploy on Tomcat 7 instance in AWS Beanstalk and the error below always comes out. 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. 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
.
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. 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.