Java Spring application build unsuccessful classpath error

Viewed 524

I use Spring + jpa + mysql + tomcat for my configuration file pom.xml here:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.5.2</version>
    <relativePath/> <!-- lookup parent from repository -->
 </parent>
 <properties>
    <java.version>11</java.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
            <exclusion>
                <artifactId>commons-logging</artifactId>
                <groupId>commons-logging</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.googlecode.json-simple</groupId>
        <artifactId>json-simple</artifactId>
        <version>1.1.1</version>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

After entity modelling, i build the application, but an error occured, which i could not figured out :)! But my tables have been properly generated after i added proper exclusions in pom.xml-file.

Here is the full error:

2021-07-01 01:21:44.632  INFO 17184 --- [           main] c.c.b.BuildingModelServiceApplication    : No active profile set, falling back to default profiles: default
2021-07-01 01:21:45.887  INFO 17184 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2021-07-01 01:21:45.956  INFO 17184 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 60 ms. Found 1 JPA repository interfaces.
2021-07-01 01:21:46.504  INFO 17184 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-07-01 01:21:46.526  INFO 17184 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-07-01 01:21:46.526  INFO 17184 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.46]
2021-07-01 01:21:46.673  INFO 17184 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-07-01 01:21:46.673  INFO 17184 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1882 ms
2021-07-01 01:21:46.804  INFO 17184 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2021-07-01 01:21:47.228  INFO 17184 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2021-07-01 01:21:47.328  INFO 17184 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2021-07-01 01:21:47.428  INFO 17184 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.4.27.Final
2021-07-01 01:21:47.613  INFO 17184 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2021-07-01 01:21:47.744  INFO 17184 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL8Dialect
2021-07-01 01:21:48.731  INFO 17184 --- [           main] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2021-07-01 01:21:48.747  INFO 17184 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2021-07-01 01:21:48.916  INFO 17184 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2021-07-01 01:21:48.963  WARN 17184 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping]: Factory method 'requestMappingHandlerMapping' threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.core.log.LogDelegateFactory.getHiddenLog(Ljava/lang/String;)Lorg/apache/commons/logging/Log;
2021-07-01 01:21:48.963  INFO 17184 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'
2021-07-01 01:21:48.963  INFO 17184 --- [           main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2021-07-01 01:21:48.963  INFO 17184 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2021-07-01 01:21:48.979  INFO 17184 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.
2021-07-01 01:21:48.994  INFO 17184 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2021-07-01 01:21:48.994  INFO 17184 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-07-01 01:21:49.016 ERROR 17184 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    org.springframework.web.servlet.handler.AbstractHandlerMapping.<init>(AbstractHandlerMapping.java:83)

The following method did not exist:

    org.springframework.core.log.LogDelegateFactory.getHiddenLog(Ljava/lang/String;)Lorg/apache/commons/logging/Log;

The method's class, org.springframework.core.log.LogDelegateFactory, is available from the following locations:

    jar:file:/C:/Users/user/Desktop/DevOps/Project/my_model_service/lib/spring-core-5.3.3.jar!/org/springframework/core/log/LogDelegateFactory.class
    jar:file:/C:/Users/user/.m2/repository/org/springframework/spring-core/5.3.8/spring-core-5.3.8.jar!/org/springframework/core/log/LogDelegateFactory.class

The class hierarchy was loaded from the following locations:

    org.springframework.core.log.LogDelegateFactory: file:/C:/Users/user/Desktop/DevOps/Project/my_model_service/lib/spring-core-5.3.3.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of org.springframework.core.log.LogDelegateFactory


Process finished with exit code 1

Hopefully somebody can figure it out, thanks, i will vote up each constructive answer!

2 Answers

I got the error, it was on the version of the spring-boot-starter-parent. I had before the version 2.5.2, now it works with the version 2.4.2. Here the updated part of the pom.xml:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.4.2</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

Now no error anymore:

2021-07-01 09:11:03.768  INFO 12576 --- [           main] c.c.b.BuildingModelServiceApplication    : No active profile set, falling back to default profiles: default
2021-07-01 09:11:04.931  INFO 12576 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2021-07-01 09:11:04.988  INFO 12576 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 48 ms. Found 1 JPA repository interfaces.
2021-07-01 09:11:05.613  INFO 12576 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-07-01 09:11:05.624  INFO 12576 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-07-01 09:11:05.624  INFO 12576 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.41]
2021-07-01 09:11:05.753  INFO 12576 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-07-01 09:11:05.754  INFO 12576 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1913 ms
2021-07-01 09:11:05.939  INFO 12576 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2021-07-01 09:11:05.984  INFO 12576 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.4.27.Final
2021-07-01 09:11:06.127  INFO 12576 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2021-07-01 09:11:06.259  INFO 12576 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2021-07-01 09:11:06.569  INFO 12576 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2021-07-01 09:11:06.591  INFO 12576 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL8Dialect
2021-07-01 09:11:07.629  INFO 12576 --- [           main] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2021-07-01 09:11:07.637  INFO 12576 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2021-07-01 09:11:07.899  INFO 12576 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2021-07-01 09:11:08.457  INFO 12576 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2021-07-01 09:11:08.468  INFO 12576 --- [           main] c.c.b.BuildingModelServiceApplication    : Started BuildingModelServiceApplication in 5.239 seconds (JVM running for 7.113)

Thanks for your help, it was a version problem as @Jean Picard said, but the appropriate version was 2.4.2!

This method : org.springframework.core.log.LogDelegateFactory.getHiddenLog(Ljava/lang/String;) was added in spring-core-5.3.5 and spring-core-5.3.3 is loaded.

You'll need to use spring-boot with version 2.4.4+ for spring-core-5.3.5, can you check if all your spring-boot dependencies and plugin are on the same version ?

Related