0
votes

I managed to apply swagger ui on Spring boot application and was able to open the page using http://localhost:8181/swagger-ui.html

After some time i kept working on my application and now its gone. i did not remove any jars. i added an Application Startup class which is used to load some things at startup as i was deploying on Wildfly 10.

Even if i try to run it as Spring boot app with tomcat it does not work. I am not sure what I changed that this stopped coming all of a sudden.

I can open /swagger-resources/configuration/ui and /swagger-resources/configuration/security and /swagger/api-docs ( i put my springfox.documenation.swagger.v2.path as /myapp/swagger/api-docs)

when i hit

i get this in logs

2018-03-20 13:01:22.130 DEBUG 9928 --- [0.1-8181-exec-5] o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/swagger-ui.html]
2018-03-20 13:01:22.131 DEBUG 9928 --- [0.1-8181-exec-5] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /swagger-ui.html
2018-03-20 13:01:22.131 DEBUG 9928 --- [0.1-8181-exec-5] .m.m.a.ExceptionHandlerExceptionResolver : Resolving exception from handler [null]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
2018-03-20 13:01:22.131 DEBUG 9928 --- [0.1-8181-exec-5] .w.s.m.a.ResponseStatusExceptionResolver : Resolving exception from handler [null]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
2018-03-20 13:01:22.132 DEBUG 9928 --- [0.1-8181-exec-5] .w.s.m.s.DefaultHandlerExceptionResolver : Resolving exception from handler [null]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
2018-03-20 13:01:22.132 DEBUG 9928 --- [0.1-8181-exec-5] o.s.web.servlet.DispatcherServlet        : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
2018-03-20 13:01:22.132 DEBUG 9928 --- [0.1-8181-exec-5] o.s.web.servlet.DispatcherServlet        : Successfully completed request
2

2 Answers

1
votes
  • It might be the swagger-UI dependency is not present that's why it is not able to load the Swagger UI.

Please Add the dependency in pom.xml

<dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.5.0</version>
        </dependency>

After that use the swagger configuration so that it can enable swagger.

@Configuration
@EnableSwagger2
public class SwaggerConfig {                                    

    @Bean
    public Docket api() { 
        return new Docket(DocumentationType.SWAGGER_2)  
          .select()                                  
          .apis(RequestHandlerSelectors.any())              
          .paths(PathSelectors.any())                          
          .build();                                           
    }
0
votes

the issue was that I had a Controller with a RequestMapping("/myapp") on class

as this was also a Wildfly application I have a jboss-web.xml with the same value in contextroot

now when i deployed on WF 10 . my context root became /myapp/myapp in order to hit the controller otherwise it wont hit the controller. So i removed it from the Controller and whenever I goto swagger-ui.html it would go through the controller and ( as the logs said) not find any handler for /swagger-ui.html)