• Home
  • About
    • lahuman photo

      lahuman

      열심히 사는 아저씨

    • Learn More
    • Facebook
    • LinkedIn
    • Github
  • Posts
    • All Posts
    • All Tags
  • Projects

[2017-06-23]Spring xml 설정으로 Swagger 사용 하기

23 Jun 2017

Reading time ~1 minute

Swagger를 Spring xml 설정을 이용하여 사용 하기

함께 일하는 분에게 Swagger를 소개 받고, 우리 서비스에서 사용 해보기로 하였다.

봉착한 문제는 대부분의 swagger의 설정이 SpringBoot의 Java Config기반으로 처리 하기 때문에 설정에 시간이 오래 걸릴 것이라고 걱정이 되었으나,

다음과 같이 간단한 방법으로 처리가 되었다.

Maven 설정 추가

<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.7.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.7.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.fasterxml/classmate -->
<dependency>
    <groupId>com.fasterxml</groupId>
    <artifactId>classmate</artifactId>
    <version>1.3.3</version>
</dependency>

Spring servlet xml설정 추가

<bean id="swagger2Config"
		class="springfox.documentation.swagger2.configuration.Swagger2DocumentationConfiguration"></bean>

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

이후 http://localhost:8080/swagger-ui.html으로 접속 할 경우 결과 화면을 볼 수 있다.

참고



springswaggersetting Share Tweet +1