Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to ignore configuration classes on the classpath?

I have a Spring Boot application that works as expected when ran with embedded tomcat, but I noticed that if I try to run it from an existing tomcat instance that I'm using with a previous project then it fails with a NoClassDefFoundError for a class that I don't use anywhere in my application.

I noticed in the /lib directory I had a single jar that contained a few Spring annotated classes, so as a test I cleaned out the /lib directory which resolved the issue. My assumption is that Spring is seeing some of the configurations/beans/imports on the classpath due to them existing in the /lib directory and either trying to autoconfigure something on its own, or is actually trying to instantiate some of these classes.

So then my question is - assuming I can't always fully control the contents of everything on the classpath, how can I prevent errors like this from occurring?

EDIT

For a little more detail - the class not being found is DefaultCookieSerializer which is part of the spring-session-implementation dependency. It is pulled into one of the classes in the jar located in /lib, but it is not any part of my application.

like image 905
billoot Avatar asked Oct 20 '25 16:10

billoot


1 Answers

Check for features provided by @EnableAutoConfiguration. You can explicitly configure set of auto-configuration classes for your application. This tutorial can be a good starting point.

like image 196
Vasily Liaskovsky Avatar answered Oct 23 '25 06:10

Vasily Liaskovsky