Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide sample configurations for spring project (not spring boot) #67

Open
kajaldhatrak opened this issue May 29, 2024 · 2 comments
Open

Comments

@kajaldhatrak
Copy link

Swagger ui not coming up in spring application.
As per documentation, tried adding spring-boot,spring-boot-autoconfigure dependencies.
also configure those classes which are not auto configure in spring project.
Tried various combinations still swagger-ui is not coming up.

Sample project would be helpful as there is very less documentation for pure spring project.

@micronaut
Copy link

Are there any updates on this? I am having the same problem with a non-spring boot spring project. Thanks

@kajaldhatrak
Copy link
Author

kajaldhatrak commented Jun 27, 2024

for following spring dependency it was throwing some parameter error which was caused by spring 6 deprecating the class which springdoc uses.

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-webmvc-core</artifactId>
    <version>1.8.0</version>
</dependency>

so here's what worked for me -

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
    <version>2.5.0</version>
</dependency>

also it needs following dependency since project is not spring boot project:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-autoconfigure</artifactId>
    <version>3.3.1</version>
</dependency>

for configuration you need to add following configuration class:

@Configuration
@ComponentScan(
        basePackages = {"org.springdoc"}
)
@EnableWebMvc
@Import({SpringDocConfiguration.class,
        SpringDocWebMvcConfiguration.class,
        org.springdoc.webmvc.ui.SwaggerConfig.class,
        SwaggerUiConfigProperties.class,
        SwaggerUiOAuthProperties.class,
        JacksonAutoConfiguration.class})
public class OpenApiConfiguration {

    @Bean
    public OpenAPI openAPI() {
        return new OpenAPI();
    }

   
}


Also all methods need @ResponseBody as annotation.
Methods without @ ResponseBody were not showing in swagger ui.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants