2

When I add Swagger to Spring Boot project, I get error I mentioned.

I tried a lot but couldn't find the problem.

Error

Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/core/metrics/ApplicationStartup

Main class

@SpringBootApplication
@Import({SwaggerConfiguration.class})
public class ExampleMain {
    public static void main(String[] args) {
        SpringApplication.run(ExampleMain.class, args);
    }
}

pom.xml

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <version>2.7.4</version>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>3.0.0</version>
</dependency>
<dependency>
    <groupId>commons-logging</groupId>
    <artifactId>commons-logging</artifactId>
    <version>1.2</version>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>3.0.0</version>
</dependency>

SwaggerConfiguration class

@Configuration
@EnableSwagger2
public class SwaggerConfiguration {

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2).select()
                .apis(RequestHandlerSelectors.basePackage("com.example.rest")).paths(PathSelectors.any())
                .build();
    }

}

Why does this problem occur, How can I fix?

Ram
  • 313
  • 1
  • 2
  • 17
zoroglur
  • 395
  • 2
  • 18
  • 2
    Please add your full list of dependencies. Generally this error comes from combining incompatible versions. – M. Deinum Jan 04 '23 at 13:30
  • You can also check https://stackoverflow.com/questions/33865724/spring-boot-exception-in-thread-main-java-lang-noclassdeffounderror-org-sp – Csisanyi Jan 04 '23 at 13:31
  • Does this answer your question? [Spring Boot ClassNotFoundException org.springframework.core.metrics.ApplicationStartup](https://stackoverflow.com/questions/65046056/spring-boot-classnotfoundexception-org-springframework-core-metrics-applications) – tbatch Jan 04 '23 at 13:31
  • I checked this answer, but This problem wasnt fix @skidwiz – zoroglur Jan 04 '23 at 13:33

0 Answers0