파닥이

[REST API] Swagger 본문

IT/Spring

[REST API] Swagger

알라이또 2019. 3. 16. 13:20
반응형


공식사이트 : swagger 





1. swagger 라이브러리 추가 (gradle)  (swagger를 사용시 jackson 라이브러리도 같이 쓰임)


compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.5.0'

compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.5.0'


2. SwaggerConfiguration 생성


//Swagger 2.0 version을 사용 annotation

@EnableSwagger2

//설정 파일 annotation

@Configuration

public class SwaggerConfiguration {

@Bean

public Docket api() {

return new Docket(DocumentationType.SWAGGER_2)

                .select()

                .apis(RequestHandlerSelectors.basePackage("com.test.filter"))

                .paths(PathSelectors.any())

                .build();

               

}

}



3. servlet-context.xml 추가


<default-servlet-handler />

<resources location="classpath:/META-INF/resources/" mapping="/swagger-ui.html"></resources>

<resources location="classpath:/META-INF/resources/webjars/" mapping="/webjars/**"></resources>


4. AOP를 사용할경우 제외


<mvc:exclude-mapping path="/swagger-ui.html" />

<mvc:exclude-mapping path="/webjars/**" />

<mvc:exclude-mapping path="/swagger-resources/**" />

<mvc:exclude-mapping path="/v2/**" />


5. /swagger-ui.html 경로로 접속






참조 블로그 

https://medium.com/@jjeaby/swagger-with-spring-java-ccb8bd9371e0

https://cofived.tistory.com/27

Comments