首页

springcloud gradle项目配置springfox-swagger示例DEMO下载

标签:springfox,swagger2,springfox-swagger2,springfox-swagger-ui,sw配置demo     发布时间:2022-04-08   
  • 云盘下载:
  • [提取码:ctw9]
  • 本地下载:
       ( 需积分:8  )

本项目为gradle的spring cloud项目,配置io.springfoxswagger效果如下图所示

主要配置步骤有

1、项目依赖配置

compile('io.springfox:springfox-swagger2:2.9.2')@b@compile('io.springfox:springfox-swagger-ui:2.9.2')

2、@SpringBootApplication启动类上加上@EnableSwagger2配置

package com.xwood.cloud.eureka.services;@b@ @b@import lombok.extern.slf4j.Slf4j;@b@import org.springframework.boot.SpringApplication;@b@import org.springframework.boot.autoconfigure.SpringBootApplication;@b@import org.springframework.cloud.client.loadbalancer.LoadBalanced;@b@import org.springframework.cloud.netflix.eureka.EnableEurekaClient; @b@import springfox.documentation.swagger2.annotations.EnableSwagger2;@b@ @b@@SpringBootApplication@b@@EnableEurekaClient@b@@EnableSwagger2@b@@Slf4j@b@public class EurekaServicesApplication {@b@ @b@   public static void main(String[] args) {@b@      try {@b@         SpringApplication.run(EurekaServicesApplication.class, args);@b@         log.info("EurekaServices  deploy  success ^_^.");@b@      } catch (Exception e) {@b@         e.printStackTrace();@b@         log.error("启动报错,error={}",e.getMessage(),e);@b@      }@b@   }@b@ @b@ @b@}

3、项目api接口访问地址http://localhost:9990/eureka-services/swagger-ui.html

server.port=9990@b@server.servlet.context-path=/eureka-services@b@#server.hostname=${spring.cloud.client.hostname}@b@spring.application.name=eureka-services@b@spring.profiles.active=local@b@@b@# eureka客户端相关配置@b@# 客户端拉取服务注册信息的时间间隔,默认30秒,如果网关服务,配置小点@b@eureka.client.registry-fetch-interval-seconds=30@b@###因为自己是注册服务中心所以不需要检索服务信息@b@eureka.client.fetch-registry=false@b@###因为自己是注册中心,是否需要将自己注册给自己的服务中心(集群的时候需要将该值设置为true)@b@eureka.client.register-with-eureka=true@b@###注册地址@b@eureka.client.serviceUrl.defaultZone=http://localhost:9999/eureka/@b@@b@@b@server.tomcat.uri-encoding=UTF-8@b@spring.http.encoding.force=true@b@spring.http.encoding.enabled=true@b@spring.http.encoding.charset=UTF-8@b@spring.messages.encoding=UTF-8