0

I have made a basic CRUD app, wish to add Swagger with it.

My endpoints are -

@RequestMapping(value = "/api/v1")

GET - /get_all_bookings

POST - /new_booking

PUT - /update_booking/{id}

DELETE - /delete_booking/{id}

So I Included the dependency springfox-swagger2 & springfox-swagger-ui, then a config package and inside it SwaggerConfig class,

@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket postsApi() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("public-api")
                .apiInfo(apiInfo()).select().paths(postPaths()).build();
    }

    private Predicate<String> postPaths() {
        return or(regex("/api/v1/*"), regex("/api/v1/get_all_bookings*"));
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("Demo API")
                .description("Placeholder")
                .termsOfServiceUrl("www.something.com")
                .contact("sandeep.roy2014@gmail.com").license("Free")
                .licenseUrl("www.somthing.com").version("1").build();
    }
}

It gives too many errors, which I'm not able to understand.

Error creating bean with name 'swagger2Controller': Lookup method resolution failed

Failed to introspect Class [springfox.documentation.swagger2.web.Swagger2Controller] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@2aae9190]

java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest

java.lang.ClassNotFoundException: javax.servlet.http.HttpServletRequest

I'm not very sure, what exactly I'm doing wrong! Although all endpoints working fine when tried in Postman.

Sandeep Roy
  • 417
  • 6
  • 27
  • If you are using Spring Boot 3 or above, the recommendation is to use springdoc. Please refer to the answer in the question https://stackoverflow.com/questions/74614369/how-to-run-swagger-3-on-spring-boot-3. – Gopinath Radhakrishnan Apr 13 '23 at 05:56

1 Answers1

0

Just make sure you have this dependency in your POM file

   <dependency>
      <groupId>org.springdoc</groupId>
      <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
      <version>2.0.0</version>
   </dependency>
tapsshore
  • 272
  • 4
  • 9