1.jar
2. File configuration
Swagger configuration
PackageCom.myPackage.config;ImportOrg.springframework.context.annotation.Bean;Importorg.springframework.context.annotation.Configuration;Importspringfox.documentation.builders.PathSelectors;Importspringfox.documentation.builders.RequestHandlerSelectors;ImportSpringfox.documentation.service.ApiInfo;ImportSpringfox.documentation.spi.DocumentationType;ImportSpringfox.documentation.spring.web.plugins.Docket;ImportSpringfox.documentation.swagger2.annotations.EnableSwagger2, @Configuration @enableswagger2 Public classswaggerconfig{@Bean PublicDocket API () {return NewDocket (documentationtype.swagger_2). Select (). APIs (Requesthandlerselectors.any ()) . Paths (Pathselectors.any ()). Build (). GroupName ("Test"). Apiinfo (Apiinfo ()); } Privateapiinfo Apiinfo () {apiinfo apiinfo=NewApiinfo ("My Project's REST API", "This is a description of your API.", "API TOS", "url", "[Email protected]", "API License", "API License URL"); returnApiinfo; }}
SPRINGMVC configuration:
Package Com.mypackage.config;import Org.springframework.context.annotation.bean;import Org.springframework.context.annotation.componentscan;import Org.springframework.context.annotation.configuration;import Org.springframework.context.annotation.Import; Import Org.springframework.web.servlet.viewresolver;import Org.springframework.web.servlet.config.annotation.defaultservlethandlerconfigurer;import Org.springframework.web.servlet.config.annotation.enablewebmvc;import Org.springframework.web.servlet.config.annotation.resourcehandlerregistry;import Org.springframework.web.servlet.config.annotation.webmvcconfigureradapter;import Org.springframework.web.servlet.view.InternalResourceViewResolver; @Configuration @enablewebmvc@import ({ Swaggerconfig.class}) @ComponentScan ("Com.myPackage.controller") public class Webspringconfig extends webmvcconfigureradapter{@Override public void Addresourcehandlers (Resourcehandlerregistry registry) {Regist Ry.addresourcehandler ("/resources/**"). AddREsourcelocations ("/resources/"); Registry. Addresourcehandler ("swagger-ui.html"). Addresourcelocations ("Classpath:/meta-inf/resources /"); Registry. Addresourcehandler ("/webjars/**"). Addresourcelocations ("Classpath:/meta-inf/resources/web Jars/"); } @Bean Public Viewresolver configureviewresolver () {internalresourceviewresolver viewresolve = new Internal Resourceviewresolver (); Viewresolve.setprefix ("/web-inf/views/"); Viewresolve.setsuffix (". jsp"); return viewresolve; } @Override public void configuredefaultservlethandling (Defaultservlethandlerconfigurer configurer) { Configurer.enable (); }}
3. Dispenser Configuration:
<servlet> <servlet-name>appServlet</servlet-name> <servlet-class> org.springframework.web.servlet.dispatcherservlet</servlet-class> <init-param> < Param-name>contextclass</param-name> <param-value> Org.springframework.web.context.support.annotationconfigwebapplicationcontext</param-value> </ init-param> <init-param> <param-name>contextConfigLocation</param-name> < param-value>com.mypackage.config.webspringconfig</param-value> </init-param> < Load-on-startup>1</load-on-startup> </servlet>
4 question: V2/api-docs 404
Reference:
https://stackoverflow.com/questions/33780237/springfox-2-2-2-no-api-docs-generated
Spring MVC4 Configuration Restfulapi Interface management tool issues overall