Swagger配置:Maven+SpringBoot+jdk1.
来源:互联网 发布:win7 64位安装apache 编辑:程序博客网 时间:2024/06/04 19:15
环境Maven+Swagger2+SpringBoot+jdk1.8
1.pom.xml配置
4.0.0 org.springframework.boot spring-boot-starter-parent1.5.7.RELEASE com.hodays swagger_hodays1.0-SNAPSHOT org.springframework.boot spring-boot-starter-webio.springfox springfox-swagger22.7.0 io.springfox springfox-swagger-ui2.7.0 org.springframework.boot spring-boot-maven-pluginmaven-compiler-plugin 1.8
2.config配置
package com.huaihkiss.swaggertest.config;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import springfox.documentation.builders.ApiInfoBuilder;import springfox.documentation.builders.PathSelectors;import springfox.documentation.builders.RequestHandlerSelectors;import springfox.documentation.service.ApiInfo;import springfox.documentation.spi.DocumentationType;import springfox.documentation.spring.web.plugins.Docket;import springfox.documentation.swagger2.annotations.EnableSwagger2;@Configuration@EnableSwagger2public class Swagger2 { @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage("com.huaihkiss.swaggertest")) .paths(PathSelectors.any()) .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("HODAYS API接口测试:") .version("1.0") .build(); }}
3.Controller接口
package com.huaihkiss.swaggertest.controller.web_hodays;import io.swagger.annotations.Api;import io.swagger.annotations.ApiOperation;import io.swagger.annotations.ApiParam;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.context.annotation.Description;import org.springframework.http.ResponseEntity;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.PostMapping;import org.springframework.web.bind.annotation.RestController;import utils.Constant;import utils.HttpRequest;import utils.SystemException;import javax.websocket.server.PathParam;import javax.ws.rs.FormParam;import java.util.HashMap;import java.util.Map;/** * CMS活动模块接口测试 * @author liumengwei * @Time 2017/10/9 * */@Api(value="CMS活动模块接口测试", description = "接口测试", tags = "CMS活动")@RestControllerpublic class WActivityController { private final static Logger logger = LoggerFactory.getLogger(WActivityController.class); /** * 活动详细信息接口 * @param aid 活动id * @return org.springframework.http.ResponseEntity * @author liumengwei * @Date 2017/10/11 */ @ApiOperation(value = "活动详细信息接口",notes = "活动详细信息接口contents") @GetMapping(value = "contents", params = {"aid"}, produces = "application/json; charset=utf-8") public ResponseEntity> contents( @ApiParam(name = "aid", value = "活动id") @PathParam("aid") Integer aid){ try { String result = HttpRequest.sendGet( String.format(Constant.WEB_HODAYS_URL + Constant.CONTENTS, aid), null ); return ResponseEntity.ok( result ); } catch (Exception ex) { logger.error(ex.getMessage()); return ResponseEntity.ok(SystemException.SYSTEM_EXCEPTION.getDescription()); } }}
4.启动main配置
package com.huaihkiss.swaggertest;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.context.annotation.ImportResource;@SpringBootApplication(scanBasePackages="com.huaihkiss.swaggertest")public class Application { public static void main(String[] args) { SpringApplication.run(Application.class,args); }}
5.application.yml配置
server: port: 9999 context-path: /api
阅读全文
0 0
- Swagger配置:Maven+SpringBoot+jdk1.
- Swagger配置(SpringMVC、SpringBoot)
- SpringBoot配置Swagger
- eclipse 使用maven构建 springboot +swagger
- springboot + swagger
- springboot + swagger
- springboot swagger
- Swagger+SpringBoot
- maven配置jdk1.8环境
- maven配置jdk1.8版本
- SpringBoot集成Swagger
- springboot整合swagger
- springboot中集成swagger
- 【Spring Boot】springboot + swagger
- springboot + swagger 注解
- Swagger搭配Springboot使用
- springboot + swagger注解
- SpringBoot 集成Swagger
- java获取当前时间戳的方法
- SpringCloud(第 034 篇)配置服务端ConfigServer设置安全认证
- : error: undefined reference to `cv::VideoCapture::open(std::__cxx11::basic_string<char, std::char_t
- 企业出现突发网络攻击,如何及时做应急响应?
- webpack 入门一篇足够,简单而又详细入门
- Swagger配置:Maven+SpringBoot+jdk1.
- 【bzoj 1029/CS 2913】建筑抢修 07JS(贪心+优先队列)
- 10.11
- The proper way of implementing user login system(mark learn)
- 域中设置权威时间服务器并发布时间同步策略
- 阿里云OSS介绍之二 价格调研
- jquery的toFixed方法的正确使用
- 解决在android中使用微信H5支付,提示商家参数格式有误
- HDU- 2057 A + B Again