api gateway 를 swagger 에 연동
2191
작성한 질문수 13
api gateway 를 swagger 에 연동하는 방법 알려주시면 감사하겠습니다ㅜㅜ
답변 2
0
안녕하세요, 이도원입니다.
apigateway-service에 swagger를 적용하시는 걸 말씀하시는 건가요? pom.xml과 SwaggerConfig.java 파일을 추가하시면 될 것 같습니다. 다만 apigateway-service에는 Controller를 별도로 추가하지 않은 상태로 어떤 actuator에 대한 기본적인 Endpoints가 확인 될 것 같습니다.
<dependency>
<groupId>io.springfox</groupId>
<!-- <artifactId>springfox-swagger2</artifactId>-->
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<!-- <version>2.9.2</version>-->
<version>3.0.0</version>
</dependency>
package com.example.apigatewayservice.config;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.CorsEndpointProperties;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementPortType;
import org.springframework.boot.actuate.endpoint.ExposableEndpoint;
import org.springframework.boot.actuate.endpoint.web.*;
import org.springframework.boot.actuate.endpoint.web.annotation.ControllerEndpointsSupplier;
import org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpointsSupplier;
import org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.*;
//@Configuration
@EnableSwagger2
public class SwaggerConfig {
private static final Contact DEFAULT_CONTACT = new Contact("Kenneth Lee",
"http://www.joneculsting.co.kr", "edowon@joneconsluting.co.kr");
private static final ApiInfo DEFAULT_API_INFO = new ApiInfo("Awesome API Title",
"Awesome API Documentation", "1.0", "urn:tos",
DEFAULT_CONTACT, "Apache 2.0",
"http://www.apache.org/licenses/LICENSE-2.0", new ArrayList());
private static final Set<String> DEFAULT_PRODUCES_AND_CONSUMES = new HashSet<>(Arrays.asList(
"application/json", "application/xml"));
@Bean
public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping(WebEndpointsSupplier webEndpointsSupplier,
ServletEndpointsSupplier servletEndpointsSupplier,
ControllerEndpointsSupplier controllerEndpointsSupplier,
EndpointMediaTypes endpointMediaTypes,
CorsEndpointProperties corsProperties,
WebEndpointProperties webEndpointProperties,
Environment environment) {
List<ExposableEndpoint<?>> allEndpoints = new ArrayList<>();
Collection<ExposableWebEndpoint> webEndpoints = webEndpointsSupplier.getEndpoints();
allEndpoints.addAll(webEndpoints);
allEndpoints.addAll(servletEndpointsSupplier.getEndpoints());
allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints());
String basePath = webEndpointProperties.getBasePath();
EndpointMapping endpointMapping = new EndpointMapping(basePath);
boolean shouldRegisterLinksMapping = this.shouldRegisterLinksMapping(webEndpointProperties, environment, basePath);
return new WebMvcEndpointHandlerMapping(endpointMapping, webEndpoints, endpointMediaTypes,
corsProperties.toCorsConfiguration(),
new EndpointLinksResolver(allEndpoints, basePath), shouldRegisterLinksMapping);
}
private boolean shouldRegisterLinksMapping(WebEndpointProperties webEndpointProperties, Environment environment, String basePath) {
return webEndpointProperties.getDiscovery().isEnabled() && (StringUtils.hasText(basePath) || ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT));
}
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(DEFAULT_API_INFO)
.produces(DEFAULT_PRODUCES_AND_CONSUMES)
.consumes(DEFAULT_PRODUCES_AND_CONSUMES)
;
}
// @Bean
// public Docket api() {
// return new Docket(DocumentationType.SWAGGER_2)
// .select()
// .apis(RequestHandlerSelectors.any())
// .paths(PathSelectors.any())
// .build();
// }
}

감사합니다.
rabbitmq에 configservice 연결에 대해 질문있습니다.
0
17
1
kafka 업데이트 강의 듣고 시포요
0
118
2
강의 교안
0
108
2
마이크로서비스간 통신 시, 인증 처리
0
120
2
api gateway 에서 인증 처리
0
77
1
섹션 19 질문드립니다
0
87
2
강의 자료 업데이트
0
106
2
부하분산 강의 섹션
0
67
1
강의자료는 어디에서?
0
99
2
강의 자료는 어디서 다운 받을 수 있나요?
0
133
2
전체 사용자 조회시 오류
0
66
1
혹시 pk 외 별도의 id 를 부여한 이유가 있을까요 ??
0
123
2
학습 방향
0
107
2
카프카 커넥터 사용 목적 문의
0
93
2
kafka 강의
0
119
2
서비스 디스커버리 종류
0
91
2
강의 자료에 대해서 궁금해요
0
126
2
GlobalFilter, LoggingFilter가 동작하지 않습니다.
0
97
2
Kafka Source Connect 버전 에러
0
98
2
소스커넥터는 사용안한 거 맞죠?
0
87
2
강의자료 업데이트 문의
0
101
2
강의에서 BCryptPasswordEncoder 에 역할(5-2)
0
64
1
강의 업데이트 계획이 궁금합니다.
0
122
2
MSA 애플리케이션에 Spring Web과 Spring Data JPA를 사용하는 것이 바람직한지 궁금합니다. (MSA 설계와 관련된 질문입니다)
0
169
2





