SpringFox Swagger 与 Springboot 应用程序集成

SpringFox Swagger integration with Springboot app

我按照link (until step 5.1) for integrating swagger documentation. Below is how my controller class looks like. I get a 404 error when I try to access the documentation similar to how it is described in the documentation using url > http://localhost:8080/greetingservice/swagger-ui.html

中列出的步骤操作

但是我看到文档使用 url http://localhost:8080/swagger-ui.html#!/greeting-controller/greetingUsingGET

我希望文档的显示方式类似于文档中特定于应用程序的上下文路径下提到的方式。你能告诉我我错过了什么吗?

import java.util.concurrent.atomic.AtomicLong;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
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 com.comcast.rapid.ctp.springfox.service.model.Greeting;

@RequestMapping("/greetingservice")
@RestController
public class GreetingController {

    private static final String template = "Hello, %s!";
    private final AtomicLong counter = new AtomicLong();

    @RequestMapping(method={RequestMethod.GET}, value="{apiName}", produces=MediaType.APPLICATION_JSON_VALUE)
    public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name,@PathVariable String apiName) {
        return new Greeting(counter.incrementAndGet(),
                            String.format(template, name));
    }
}

I get a 404 error when I try to access the documentation similar to how it is described in the documentation using url > http://localhost:8080/greetingservice/swagger-ui.html

您需要按如下方式设置您的应用程序上下文路径:

src/main/resources 中创建 application.properties 并添加以下行:

server.context-path=/greetingservice

参考:

http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html