2017-09-25 213 views
0

我只是试图获取我的小REST API在swagger2包含在春季编写的文档。当我尝试访问我的swagger页面时,浏览器控制台中显示以下错误。SpringBoot Swagger2其余API文档未加载

Whitelabel Error Page 

This application has no explicit mapping for /error, so you are seeing this as a fallback. 

Mon Sep 25 21:09:08 IST 2017 
There was an unexpected error (type=Not Found, status=404). 
No message available 

我的代码片段在下面提到。

package com.example.demo; 

import java.util.Collections; 
import java.util.List; 

import org.apache.commons.lang3.StringUtils; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 
import org.springframework.web.bind.annotation.RequestParam; 
import org.springframework.web.bind.annotation.RestController; 

import io.swagger.annotations.Api; 
import io.swagger.annotations.ApiOperation; 

@RestController 
@RequestMapping(value="/rooms") 
@Api(value="rooms", tags=("rooms")) 
public class RoomController { 

    @Autowired 
    private RoomRepositery roomRepo; 

    @RequestMapping(method = RequestMethod.GET) 
    @ApiOperation(value="Get All Rooms", notes="Get all rooms in the system", nickname="getRooms") 
    public List<Room> findAll(@RequestParam(name="roomNumber", required=false)String roomNumber){ 
     if(StringUtils.isNotEmpty(roomNumber)) { 
      return Collections.singletonList(roomRepo.findByRoomNumber(roomNumber)); 
     } 
     return (List<Room>) this.roomRepo.findAll(); 
    } 
} 

App类

package com.example.demo; 

import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.SpringBootApplication; 
import org.springframework.context.annotation.Bean; 

import springfox.documentation.builders.RequestHandlerSelectors; 
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 static springfox.documentation.builders.PathSelectors.any; 

@SpringBootApplication 
@EnableSwagger2 
public class RoomServiceApp { 

    @Bean 
    public Docket api(){ 
     return new Docket(DocumentationType.SWAGGER_2).groupName("Room").select() 
       .apis(RequestHandlerSelectors.basePackage("com.example.demo")) 
       .paths(any()).build().apiInfo(new ApiInfo("Room Services", 
         "A set of services to provide data access to rooms", "1.0.0", null, 
         new Contact("Frank Moley", "https://twitter.com/fpmoles", null),null, null)); 
    } 

    public static void main(String[] args) { 
     SpringApplication.run(RoomServiceApp.class, args); 
    } 
} 

我无法找到我是缺少在这里。谁能帮我吗?

感谢

回答