api项目加入swagger

master
shijie 4 years ago
parent 0489133d6d
commit b3512f716a
  1. 35
      dq-financial-api/src/main/java/com/daqing/financial/config/SwaggerConfig.java
  2. 2
      dq-financial-crms/src/main/java/com/daqing/financial/crms/DqFinancialCrmsApplication.java
  3. 1
      dq-financial-crms/src/main/java/com/daqing/financial/crms/controller/CustomerController.java
  4. 27
      dq-govern-gateway/src/main/java/com/daqing/financial/gateway/config/FinancialCorsConfiguration.java
  5. 2
      dq-govern-gateway/src/main/resources/application.yml

@ -0,0 +1,35 @@
package com.daqing.financial.config;
import io.swagger.annotations.ApiOperation;
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
@EnableSwagger2
//@Profile({"dev","test"})
//@ConditionalOnProperty(name = "swagger.enable", havingValue = "true")
public class SwaggerConfig {
@Bean
public Docket productApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()//添加ApiOperiation注解的被扫描
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("大庆智慧金融平台api文档").description("大庆智慧金融平台api文档")
.version("1.0").build();
}
}

@ -4,10 +4,12 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;
@EnableFeignClients(basePackages = "com.daqing.financial.crms.feign") @EnableFeignClients(basePackages = "com.daqing.financial.crms.feign")
@EnableDiscoveryClient @EnableDiscoveryClient
@SpringBootApplication @SpringBootApplication
@ComponentScan(basePackages = "com.daqing.financial")
public class DqFinancialCrmsApplication { public class DqFinancialCrmsApplication {
public static void main(String[] args) { public static void main(String[] args) {

@ -32,6 +32,7 @@ public class CustomerController implements CustomerControllerApi {
/** /**
* 列表 * 列表
*/ */
@Override
@GetMapping("/list") @GetMapping("/list")
//@RequiresPermissions("crms:customer:list") //@RequiresPermissions("crms:customer:list")
public ResponseResult list(@RequestParam Map<String, Object> params) { public ResponseResult list(@RequestParam Map<String, Object> params) {

@ -0,0 +1,27 @@
package com.daqing.financial.gateway.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
@Configuration
public class FinancialCorsConfiguration {
@Bean
public CorsWebFilter corsWebFilter(){
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration corsConfiguration = new CorsConfiguration();
//1、配置跨域
corsConfiguration.addAllowedHeader("*");
corsConfiguration.addAllowedMethod("*");
corsConfiguration.addAllowedOrigin("*");
corsConfiguration.setAllowCredentials(true);
source.registerCorsConfiguration("/**",corsConfiguration);
return new CorsWebFilter(source);
}
}

@ -17,4 +17,4 @@ spring:
predicates: predicates:
- Path=/api/hrms/** - Path=/api/hrms/**
filters: filters:
- RewritePath=/api/(?<segment>.*),/$\{segment} - RewritePath=/api/(?<segment>.*),/ $\{segment}
Loading…
Cancel
Save