Step by step teach you how to integrate SSM with swagger

Source: Internet
Author: User
1. What is Swagger?

? Swagger is a very useful framework for writing API documents. Other self-built Baidu

Ii. SSM integration with Swagger?

1: Introduce dependency in the maven pom file: (Note the version. Otherwise, Tomcat cannot be started normally.)

<! -- Introduce swagger --> <! -- Springfox's core jar package --> <dependency> <groupid> Io. springfox </groupid> <artifactid> springfox-swagger2 </artifactid> <version> 2.7.0 </version> </dependency> <! -- Springfox-UI jar package (which contains static swagger interface files) --> <dependency> <groupid> Io. springfox </groupid> <artifactid> springfox-swagger-UI </artifactid> <version> 2.7.0 </version> </dependency> <! -- Springfox dependent jar package; if your project has already been integrated, you do not need to repeat it --> <dependency> <groupid> COM. fasterxml. jackson. core </groupid> <artifactid> Jackson-databind </artifactid> <version> 2.9.0 </version> </dependency>

2: Create the swaggerconfig. Java file, that is, the swagger configuration file. It is best to put it in a separate folder.

@ Webappconfiguration @ enableswagger2 @ enablewebmvc @ componentscan (basepackages = "com.zgz.cn. controller ") public class swaggerconfig {@ bean public docket API () {return New docket (documentationtype. swagger_2 ). select (). APIS (requesthandlerselectors. any ()). build (). apiinfo ();} private apiinfo () {return New apiinfobuilder (). title ("XXX project interface document "). description ("XXX project interface test "). version ("1.0.0 "). termsofserviceurl (""). license (""). licenseurl (""). build ();}}

3: Configure in the springmvc configuration file: (configure the packages of All controllers)

<! -- Configure the swagger Bean --> <! -- Handle static resources by default servlet --> <MVC: default-servlet-handler/> <! -- Automatically inject configuration to the container --> <context: annotation-config/> <! -- Inject the swaggerconfig configuration class --> <Bean class = "com.zgz.cn. Swagger. swaggerconfig"/> <! -- Configure swagger resources not to be intercepted --> <! -- <Bean id = "swagger2config" class = "springfox.doc umentation. swagger2.configuration. swagger2documentationconfiguration "/> --> <MVC: Resources location =" classpath:/META-INF/resources/"Mapping =" swagger-ui.html "/> <MVC: Resources location =" classpath: /META-INF/resources/webjars/"Mapping ="/webjars/** "/>

4: All requests configured in Web. XML are processed by dispatcherservlet.

<servlet-mapping>        <servlet-name>springMVC</servlet-name>        <url-pattern>/</url-pattern>    </servlet-mapping>

5: Use annotations in controllers: (Common swagger annotations)

6: Test (access address: Project name/swagger-ui.html)

Step by step teach you how to integrate SSM with swagger

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.