[Swagger] probably the best Spring Boot swagger integrated solutions

[Swagger] probably the best Spring Boot swagger integrated solutions

![](https://img2018.cnblogs.com/blog/746311/201909/746311-20190908162326923-1865614206.jpg)

  It is said that programmers hate two things: one is people do not write the document, the other is to write the document.

  Visible document really is in love with life programmer kill existence. For users on the one hand, a comprehensive and accurate documentation is simply a map when traveling, recipes when cooking, when the Raiders clearance. Can greatly improve the efficiency of docking and minimize the probability of stepped pit. However, a comprehensive and accurate documentation easier said than done.

  To interface documentation for programmers do not want to write unit tests written with the same reason, a large extent that it is a completely manual labor, no creativity at all, dull and boring. More important thing is it's not a one-time written on it, still need to keep maintenance when your business changes leading to changes in the code, so that the value of the request, response value, the interface name, field notes, check the information. . . . . They are likely to be modified. This time synchronization is necessary to interface documentation updates. Otherwise it will become not accurate. If the docking interface often the students could fully understood, it appears not only in internal, external docking interfaces, or provide an external interface such problems from time to time.

  The world is suffering interface documentation for some time now ! Suddenly one day, a wearing stockings, imposing appearance heroes appeared, changed the situation. Through his own set of annotations, you can automatically generate an online interface documentation, and with the code changes, it will follow the change. Greatly reducing the workload of people. To express respect for the hero, rivers and lakes known - stockings brother (Swagger transliteration).

  After generating a typical swagger interface document page as shown in FIG. About legend stockings brother, we stop here today. In fact, the picture can be seen by the native interface, function is relatively limited. First, we do not have a login screen, basically did not change the default address swagger few people use. So people find your address easily accessible interface to your swagger page, which brings security risks. Another point is that this interface, how should I say, at least not my favorite models. Or it is a direct connection from Spring Boot is still a little cumbersome to manually configure a variety of bean, is not Spring Boot.

  All these, and finally one day. When github wandering, we found a nice swagger toolkit, with a put it down. Project address below demonstrates how to use it.

The introduction of dependence

<dependency>
    <groupId>com.battcn</groupId>
    <artifactId>swagger-spring-boot-starter</artifactId>
    <version>2.1.5-RELEASE</version>
</dependency>

  2.1.5-RELEASEIs currently the latest version, you can see in subsequent releases on the project addresses.

Configuration chapter

spring:
  swagger:
    enabled: true

  Configuration is over, if you just want to use the most basic functions of swagger words. Visit http://{host:port}/swagger-ui.htmlthe following interface will be

  UI of the project is to use than the original Vue rewrite both the color value or function has greatly improved. For example, add a search, interface statistics and many other useful features. If we want to open the login authentication to prevent outside access to interface documentation to be, just add three configuration on it.

spring:
  swagger:
    enabled: true
    security:
      filter-plugin: true
      username: kiwi
      password: 123456

  Once again, we access interface page, the interface was blocked into the following login screen.

  Enter account number and password configuration, and saw a familiar interface page.

end

  I am not feeling very convenient, very easy. In fact, there are many features, because of limited space, more importantly, the authors themselves have written a very good use of the document, is not necessary here to list them out again (well, in fact, I am lazy), you can go to the project page and then learning . Also you can see his own blog address in the author's page, is a treasure blogger Oh!

No public concern "KIWI Sui Suinian" share more than just technology

Guess you like

Origin www.cnblogs.com/kiwifly/p/11487042.html