Unable to bring up swagger-ui from spring-boot application

前端 未结 5 930
广开言路
广开言路 2020-12-29 23:14

I have a spring boot application that i am running using embedded tomcat server. I am partially successful in getting springfox-swagger integrated with the app. If i do a

5条回答
  •  不思量自难忘°
    2020-12-29 23:49

    springfox-swagger-ui is a web jar and requires that you set up resource handlers to inform the dispatch servlet how and which resource to serve up when you ask for ../swagger-ui.html. Usually in a spring-boot application auto-configuration takes care of setting it up for you. The reason its not loading in your case is because you've signaled to spring-boot that the application is going to be manually configured via the WebMvcConfigurerAdapter/@EnableWebMvc combination.

    You should be able to place the @SpringBootApplication annotation on your main spring configuration and get rid of the WebConfig class all-together.

    Since your WebConfig isn't adding any value other than making sure the JSON is indented, I'd suggest removing it all-together and replacing it with a Jackson2ObjectMapperBuilder bean instead.

    For examples on how to do the same thing in spring-mvc/spring-boot etc. take a look at the springfox-demos project. In particular take a look at SpringConfig to see how to manually configure the resource handlers.

提交回复
热议问题