In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you about how to integrate Swagger2 in SpringBoot. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
The first step is to add dependency
Io.springfoxspringfox-swagger2 {version} io.springfoxspringfox-swagger-ui {version}
Step 2: add comments
@ EnableSwagger2 / / start SwaggerUI and add the comment to the startup class or Swagger configuration class
Step 3: write the configuration
@ Configuration@EnableSwagger2public class SwaggerConfig {@ Bean public Docket api () {/ * / / you can add multiple header or parameter ParameterBuilder aParameterBuilder = new ParameterBuilder () AParameterBuilder / / parameter types support header, cookie, body Query etc .parameterType ("header") / / Parameter name .name ("user-token") / / default value .defaultValue ("t122222") .description ("user login credential") / / specifies the type of parameter value .modelRef (new ModelRef ("string")) / / not required Here is the global configuration. Required (false). Build () List aParameters = new ArrayList (); aParameters.add (aParameterBuilder.build ()) * / return new Docket (DocumentationType.SWAGGER_2) / / return new Docket (DocumentationType.SPRING_WEB) .apiInfo (apiInfo ()) .pathMapping ("/") .select () / choose which paths and api will generate document .apis (RequestHandlerSelectors.any ()) / / monitor all APIs / / do not display the wrong interface address. Invalid (Predicates.not (PathSelectors.regex ("/ error.*")) / / wrong error path does not monitor. Invalid (Predicates.not (PathSelectors.regex ("/ actuator.*") / / wrong error path does not monitor .monitor (PathSelectors.regex ("/. *")) / / Monitor all paths under the root. Monitor (PathSelectors.any ()) / / monitor all paths / / modify to your own package path / / .apis (RequestHandlerSelectors.basePackage ("com.happyloves.zc.service.account.api")) .build () / /. GlobalOperationParameters (aParameters) .enable (true) } private ApiInfo apiInfo () {return new ApiInfoBuilder () .title ("API interface") .description ("API interface document") / / terms of service URL / / .termsOfServiceUrl ("https://www.google.com"). Version") / / Contact (new Contact) "url", "email") .build () }}
Add dependency
Com.github.xiaoyminswagger-bootstrap-ui1.9.6 above is how to integrate Swagger2 in the SpringBoot shared by Xiaobian. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.