Issue
I have a library project that I build and generated jar file in the out folder. Then I was using this Jar file by adding to another Spring Boot project via the Libraries section.
While it was working, the I started to get the following error and I am not sure if something is changed after building the library project:
The following method did not exist:
'void org.springframework.beans.factory.support.DefaultListableBeanFactory.setApplicationStartup(org.springframework.core.metrics.ApplicationStartup)'
The method's class, org.springframework.beans.factory.support.DefaultListableBeanFactory, is available from the following locations:
jar:file:/Users/einstein/project/demo/out/artifacts/gks_jar/gks.jar!/org/springframework/beans/factory/support/DefaultListableBeanFactory.class
jar:file:/Users/einstein/.m2/repository/org/springframework/spring-beans/5.3.8/spring-beans-5.3.8.jar!/org/springframework/beans/factory/support/DefaultListableBeanFactory.class
The class hierarchy was loaded from the following locations:
org.springframework.beans.factory.support.DefaultListableBeanFactory: file:/Users/einstein/project/demo/out/artifacts/gks_jar/gks.jar
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory: file:/Users/einstein/project/demo/out/artifacts/gks_jar/gks.jar
org.springframework.beans.factory.support.AbstractBeanFactory: file:/Users/einstein/project/demo/out/artifacts/gks_jar/gks.jar
org.springframework.beans.factory.support.FactoryBeanRegistrySupport: file:/Users/einstein/project/demo/out/artifacts/gks_jar/gks.jar
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry: file:/Users/einstein/project/demo/out/artifacts/gks_jar/gks.jar
org.springframework.core.SimpleAliasRegistry: file:/Users/einstein/project/demo/out/artifacts/gks_jar/gks.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.springframework.beans.factory.support.DefaultListableBeanFactory
So, what is missing and how can I solve the problem?
Here is my lombok depebdency in pom.xml file:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
Solution
If your library jar has it's size in MBs then it must be a fat jar. You should change the scope of jar's dependencies in pom.xml to provided and then build jar. For example
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
**<scope>provided</scope>**
</dependency>
Above you can see scope is set to provided that means the dependencies which are required by your library will be provided by parent application which will be using it.
Answered By - Nouman Ahmed
Answer Checked By - Katrina (JavaFixing Volunteer)