0

I followed the steps listed in this 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

However I see the documentation using url http://localhost:8080/swagger-ui.html#!/greeting-controller/greetingUsingGET

I would like the documentation to be displayed similar to how it is mentioned in the documentation under context path specific to the app. Can you please let me know what I am missing?

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));
    }
}
4

1 回答 1

1

当我尝试使用 url > http://localhost:8080/greetingservice/swagger-ui.html访问类似于文档中描述的文档时出现 404 错误

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

创建application.propertiessrc/main/resources添加以下行:

server.context-path=/greetingservice

参考:

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

于 2016-07-06T02:49:28.153 回答