0

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>
Einstein
  • 13
  • 5
  • Can you please make sure that the library jar file must not a fat jar? The fat jar contains dependency jar files inside the jar. So the error states that you have multiple versions of the spring jar file. – Dhaval Gajjar Oct 03 '22 at 01:30

1 Answers1

0

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.

  • Thanks for reply, but there is no `provided` line in my lombok dependency of the project (the project that uses the library project). Any idea? – Einstein Oct 03 '22 at 06:45
  • The lombok dependency was just for giving you an example. You need to add provided in every dependency of the library you create not in the project which is using that jar. – Nouman Ahmed Oct 03 '22 at 08:31
  • Thanks a lot, I solved it but get another problem. Could you pls have a look at https://stackoverflow.com/questions/73933386/spring-boot-logback-configuration-error-detected-error – Einstein Oct 03 '22 at 09:19
  • Any reply please? Thnaks – Einstein Oct 03 '22 at 09:33