4

I recently upgraded to Spring Boot 2, our app is deployed out through Bamboo onto PCF the build runs fine however during the deployment stage I receive the following error:

java.lang.ClassNotFoundException: org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer

We aren't using the EmbeddedServletContainerCustomizer class anywhere in the code and I can't figure out where this is coming from. Wondering if this is a pom issue?

I have tried all other questions on here of a similar nature.

halfer
  • 19,824
  • 17
  • 99
  • 186
Rebecca Douglas
  • 429
  • 1
  • 5
  • 16
  • What version of the Java Buildpack are you using on PCF? I believe it should be logged when you push your application. The Buildpack contains a customiser so you may need to use a newer version of it to pick up Spring Boot 2 support. – Andy Wilkinson Jun 13 '18 at 15:45
  • Buildpack is java_current – Rebecca Douglas Jun 14 '18 at 07:28
  • We are facing the same issue with SpringBoot2.0 plus + PCF. Has anyone found a resolution which has worked? Please help! – TuneIt Aug 31 '18 at 02:34
  • Hi @Tunelt my answer at the bottom was our solution. Ensuring the app is being packaged as a jar, the error was coming from override on SpringApplicationBuilder configure method – Rebecca Douglas Aug 31 '18 at 09:29
  • Thanks Rebecca That one worked for me! – TuneIt Nov 18 '18 at 15:16

2 Answers2

2

org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer was removed from spring-boot dependency in 2.X. Most likely you haven't updated the dependencies fully and there is a dependency that refers to spring-boot-1.X somewhere in your build.

The fact that it works on Bamboo implies that your CI is polluted and doesn't reflect the deployment environment.

Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111
  • Does seem like the most likely cause of this. Do you know the best way to check through the dependencies for something using this? – Rebecca Douglas Jun 13 '18 at 11:36
  • If you are using Maven run `mvn dependency:tree`. For Gradle see [this answer](https://stackoverflow.com/a/35235229/1602555). You should be able to obtain the offending class name from the stack trace, then work your way back to the JAR. – Karol Dowbecki Jun 13 '18 at 11:41
  • Still struggling to see how I can't produce this error locally :/ – Rebecca Douglas Jun 13 '18 at 11:52
  • Use the stack trace to find the offending class and JAR. Most likely it's available only on CI server. When you identify the JAR you can try printing the class path as per [this article](https://www.mkyong.com/java/how-to-print-out-the-current-project-classpath/) to see why is it loaded in the CI. – Karol Dowbecki Jun 13 '18 at 11:54
  • I had a similar issue to this, same error message. Luckily, the exception stack trace showed the caller class, that was trying to use this class/object type that no longer exists in spring 2.X, as Karol Dowbecki stated – ennth May 24 '21 at 17:09
2

This issue turned out to be caused by our packaging of the spring app into a war which requires implementing the SpringBootServletInitializer class to override the configure method:

@Override
  protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
      return application.sources(WebApplication.class);
  }

This in turn was throwing the above error. Taking steps now to remove this and package our app as a jar instead!

Rebecca Douglas
  • 429
  • 1
  • 5
  • 16