我按照此link中列出的步骤(直到步骤5.1)来集成swagger文档。下面是我的控制器类的样子。当我尝试访问文档时遇到404错误,类似于使用url>文档中描述的文档。 http://localhost:8080/greetingservice/swagger-ui.html
但是我看到使用网址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));
}
}
答案 0 :(得分:1)
当我尝试访问类似的文档时出现404错误 如何使用url>在文档中描述它 http://localhost:8080/greetingservice/swagger-ui.html
您需要按如下方式设置应用程序上下文路径:
在application.properties
中创建src/main/resources
并添加以下行:
server.context-path=/greetingservice
参考:
http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html