2016-09-21 4 views
0

私はSwagger 2を非スプリングブートで使用しています。また、Tomcatに自分のアプリケーションをデプロイして正常に実行できます。しかしコントローラーはswagger-ui.htmlに表示されず、空白のページに緑色の揺れのタイトルが表示されます。私はこの問題について二日過ごしました。あなたは私にいくつかアドバイスをくれますか?コントローラはswagger-ui.htmlには表示されません

@Controllerは怒鳴るように、クラスを意味します

@Api 
@Controller 
@RequestMapping("/user") 
public class UserController { 

protected Logger logger = LoggerFactory.getLogger(UserController.class); 

@Autowired 
private UserService userService; 

@RequestMapping("/showInfos") 
public @ResponseBody Object showUserInfos(){ 
    logger.info("-----------------------showUserInfos-----------------------"); 
    List<UserInfo> userInfos = userService.getUsers(); 
    return userInfos; 
} 

私の春-mvc.xml設定を次のように次のように

<mvc:annotation-driven/> 
<[email protected] inject bean --> 
<context:component-scan base-package="com.roy.demo , version" /> 

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

<!-- Include a swagger configuration --> 
<bean name="/applicationSwaggerConfig" class="com.roy.demo.config.ApplicationSwaggerConfig" /> 

をまた私の闊歩の設定クラスは次のとおりです。

@EnableSwagger2 
public class ApplicationSwaggerConfig { 

private static final Logger LOGGER = Logger.getLogger(ApplicationSwaggerConfig.class); 

@Bean 
public Docket api() { 
    LOGGER.info("################################ into Docket api() #####################################"); 
    return new Docket(DocumentationType.SWAGGER_2) 
      .select() 
      .apis(RequestHandlerSelectors.basePackage("com.roy.demo.controller")) 
      .paths(PathSelectors.any()) 
      .build(); 
} 

}

私のMavenのpom.xml swagger2依存関係を次のように私は、エンドポイントのURLを入力するとき

 <!-- Swagger 2.0 --> 
    <dependency> 
     <groupId>io.swagger</groupId> 
     <artifactId>swagger-core</artifactId> 
     <version>1.5.3</version> 
    </dependency> 
    <dependency> 
     <groupId>io.springfox</groupId> 
     <artifactId>springfox-swagger2</artifactId> 
     <version>2.5.0</version> 
    </dependency> 

    <dependency> 
     <groupId>io.springfox</groupId> 
     <artifactId>springfox-swagger-ui</artifactId> 
     <version>2.5.0</version> 
    </dependency> 

ベローは結果である。また、http://localhost:8080/Spring_SpringMVC_Mybatis/swagger-ui.html

enter image description here

+0

何@Controllerによる平均値であることは威張っ-UIで表示することはできません。 – Vaibs

+0

闊歩 – Vaibs

+0

のためのあなたのconfigクラスを共有し、同じため、この答えに従ってください: - http://stackoverflow.com/a/42922167/2357869 –

答えて

1

私が闊歩に新しいが、私は使用したコードの下に私の奇妙な構成のために、それは私のためにうまくいきます。私はクラスで構成を完了しました。

構成クラス。

@Configuration 
@EnableWebMvc 
@EnableSwagger2 
@ComponentScan(basePackages = "com.*") 
@PropertySource(value = { "classpath:log4j.properties" }) 
public class SpringConfig extends WebMvcConfigurerAdapter { 
    @Bean 
      public Docket api() { 
       return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()).directModelSubstitute(LocalDate.class, String.class).genericModelSubstitutes(ResponseEntity.class) 
         .useDefaultResponseMessages(false) 
        .select()   
        .apis(RequestHandlerSelectors.any())    
        .paths(PathSelectors.any())       
        .build();           
      } 
      @Override 
      public void addResourceHandlers(ResourceHandlerRegistry registry) { 
       registry.addResourceHandler("swagger-ui.html") 
        .addResourceLocations("classpath:/META-INF/resources/"); 
       registry.addResourceHandler("/webjars/**") 
        .addResourceLocations("classpath:/META-INF/resources/webjars/"); 
      } 
    @SuppressWarnings("deprecation") 
    private ApiInfo apiInfo() { 
     ApiInfo apiInfo = new ApiInfo(
      "API", 
      "API for xxxx", 
      "API TOS", 
      "Terms of service", 
      "xxx", 
      "License of API", 
      ""); 
     return apiInfo; 
    } 

} 

Mavenの依存関係:

<dependency> 
      <groupId>io.springfox</groupId> 
      <artifactId>springfox-swagger2</artifactId> 
      <version>2.4.0</version> 
     </dependency> 
<dependency> 
      <groupId>io.springfox</groupId> 
      <artifactId>springfox-swagger-ui</artifactId> 
      <version>2.4.0</version> 
     </dependency> 

コントローラクラス

@RestController 
@Api(value="users", description="Endpoint for user management") 
public class Controller { 
} 

エンドポイントURL:

https://localhost:8080/AppName/swagger-ui.html 
+0

http://i.stack.imgur.com/l3wag.png 私はまだこの問題を解決することはできません、私は上記の –

+0

のカット画像を参照して設定を変更しましたか? – Vaibs

+0

はい、私はあなたがswagger設定クラスに行ったように、やってもうまくいきませんでした。 –

関連する問題