2015-01-09 2 views
14

스프링 부트 1.2.1에서 작동하는 Swagger UI를 얻으려고합니다. 나는 https://github.com/martypitt/swagger-springmvc에 지시를 따르고 나는 나의 봄 윤곽에 @EnableSwagger를 추가했다.스프링 부트로 작동하는 Swagger UI를 얻을 수 없습니다.

http://localhost:8080/api-docs에 갈 때 JSON이 표시되지만 멋진 HTML은 표시되지 않습니다.

나는 메이븐을 사용하고 자신감-UI에 대한 종속성 추가하고이 종속성의 내 전체 목록

<dependency> 
    <groupId>org.ajar</groupId> 
    <artifactId>swagger-spring-mvc-ui</artifactId> 
    <version>0.4</version> 
</dependency> 

입니다

: 나는 또한 URL로 http://localhost:8080/docs/index.html을 시도

<dependencies> 
     <dependency> 
      <groupId>com.mangofactory</groupId> 
      <artifactId>swagger-springmvc</artifactId> 
      <version>0.9.4</version> 
     </dependency> 
     <dependency> 
      <groupId>org.ajar</groupId> 
      <artifactId>swagger-spring-mvc-ui</artifactId> 
      <version>0.4</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-web</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-websocket</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-actuator</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-test</artifactId> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 

,하지만 그건 그냥 준다 "Whitelabel Error Page"

업데이트 :

나는 문제 보여 Github에서의 테스트 프로젝트를 생성 : 저도 같은 문제가 https://github.com/wimdeblauwe/springboot-swagger-test

+1

http : // localhost : 8080/sdoc.jsp 또는 http : // localhost : 8080/app/sdoc.jsp를 사용해 보셨습니까? – Ron

+0

@Ron 지금 시도했지만 작동하지 않습니다. –

+0

바로 여기에 쓰여진 내용을 따랐습니다 - https://github.com/adrianbk/swagger-springmvc-demo/tree/master/swagger-ui - 여기에 답장을받지 못하면 그 문제를 열어 보시기 바랍니다. 저장소. 애드리안은 매우 민감합니다. – Ron

답변

1

을하지만,이 링크는 나를 위해 작동 : http://localhost:8080 $ : http://localhost:8080/sdoc.jsp

는이와 함께 자신감의 UI 자원 URL 상자를 미리 채 웁니다 {pageContext.request.contextPath}/api-docs

을 수정하고 $ {pageContext.request.contextPath}을 (를) 삭제하고 탐색하면 내 API 문서가 표시되어 내 끝점을 성공적으로 시도 할 수도 있습니다. 그래서 확실히 문제지만 아마 $ {pageContext.request/contextPath}를 선택하지 않을 것입니다. URL : 나는이 작품이 가지고 정적 자신감의 UI를 HTML에 window.location.origin + "$ {pageContext.request.contextPath}/API-문서"

자바 스크립트가 가지고있는 소스를 보면

discoveryUrl :로 코딩 "./ 자원 list.json"나는이 희망

도움이 조금

+0

스프링 부트가 JSP를 올바르게 렌더링하지 않습니다. –

2

I 스프링 v4.14 & swagger-와 자신감-UI를 v0.4을 (이 springmvc v0.9.4) 잘 작동하고 있습니다. 처음에는 비슷한 문제가있었습니다. 이 수업은 속임수처럼 보인다.

@Configuration 
@EnableSwagger 
public class SwaggerConfig extends WebMvcConfigurerAdapter { 

    @Autowired 
    private SpringSwaggerConfig springSwaggerConfig; 

    @Bean 
    public SwaggerSpringMvcPlugin customImplementation() { 
     return new SwaggerSpringMvcPlugin(springSwaggerConfig).apiInfo(
       apiInfo()); 
    } 

    private ApiInfo apiInfo() { 
     return new ApiInfo(/* strings */); 
    } 

    @Override 
    public void configureDefaultServletHandling(
      DefaultServletHandlerConfigurer configurer) { 
     configurer.enable(); 
    } 
} 

관련 항목은 우선 configureDefaultServletHandling입니다. 그리고 내 주요 WebApplicationInitializer에, 내가 가진 마지막으로

@Import(SwaggerConfig.class) 

, 내 의존성이를 포함하여 "http://localhost:8080 $ {pageContext.request.contextPath}/API-문서"를 보여주는 UI의 위치 상자와 함께 문제를 해결 :

<dependency> 
    <groupId>org.apache.tomcat.embed</groupId> 
    <artifactId>tomcat-embed-jasper</artifactId> 
    <!--<version>8.0.15</version>--> 
    <scope>provided</scope> 
</dependency> 

이는 JSP 처리와 관련이 있습니다. 종속성은 spring-boot에 포함되어 있지만 일반적으로 provided은 아닙니다.

희망이 있습니다.

9

귀하의 문제는 SwaggerConfiguration 파일에 있습니다.@EnableWebMvc을 가져와야합니다. 이는 정적 컨텐츠를 다르게 처리하는 기본 'SpringWebMvc'에 의해 기본 Spring Boot 뷰 해석기를 겹쳐 쓰게하기 때문입니다.

  • /META-INF/자원/
  • /자원/
  • /
  • /정적
  • /공공 기본적으로

    는 봄 부팅은 다음 디렉토리 중 하나에서 정적 콘텐츠를 제공합니다/

(webjars 포함).

은 저도 같은 문제를 겪고 난 문서에서 이걸 발견 : 당신은 스프링 MVC을 완전히 제어 할 경우 http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-developing-web-applications.html#boot-features-spring-mvc-auto-configuration

, 당신은 당신의 자신의 @Configuration@EnableWebMvc로 주석을 추가 할 수 있습니다. Spring Boot MVC 기능을 유지하기 위해 추가 MVC 구성 (인터셉터, 포맷터, 뷰 컨트롤러 등)을 추가하려는 경우 WebMvcConfigurerAdapter 유형의 을 추가 할 수 있지만 @EnableWebMvc없이 추가 할 수 있습니다.

이 정보가 도움이되기를 바랍니다.

-2

난 당신이 EnableSwagger2 태그 @ 사용하고 여기에서의 단계와 코드를 따라 제안 : 또한 https://github.com/sanketsw/SpringBoot_REST_API

내가 완벽하게 잘 작동 다음과 같은 의존성 사용하고 있습니다 : 나는 별도의 설정을했을

<dependency> 
    <groupId>io.springfox</groupId> 
    <artifactId>springfox-swagger-ui</artifactId> 
    <version>2.2.2</version> 
    <scope>compile</scope> 
</dependency> 
<dependency> 
    <groupId>io.springfox</groupId> 
    <artifactId>springfox-swagger2</artifactId> 
    <version>2.2.2</version> 
    <scope>compile</scope> 
</dependency> 
+0

외부 리소스에 연결하는 것은 좋지만 링크가 크게 변하거나 시간이 지남에 따라 완전히 변경 될 수 있습니다. https://github.com/adrianbk/swagger-springmvc-demo/issues/15를 참조하십시오. 외부 정보에 의존 할 필요없이 해답에 해결책을 구현하기에 충분한 정보를 포함하십시오. –

+0

자세한 답변은 다음 페이지를 참조하십시오. http://stackoverflow.com/questions/34307496/advice-about-swagger-api/35907962#35907962 –

-1

을 Swagger와 내 문제는 @EnableAutoConfiguration이 없으면 올바르게 작동하지 않는다는 것입니다.

@Configuration 
@EnableSwagger2 
@EnableAutoConfiguration 
public class SwaggerConfig { 
    @Bean 
    public Docket api() { 
     return new Docket(DocumentationType.SWAGGER_2) 
       .select() 
       .apis(RequestHandlerSelectors.any()) 
       .paths(PathSelectors.any()) 
       .build(); 
    } 
} 
관련 문제