java - SpringFox Swagger 与 Springboot 应用程序集成

标签 java spring spring-boot swagger springfox

我按照此link中列出的步骤进行操作(直到步骤 5.1)用于集成 swagger 文档。下面是我的 Controller 类的样子。当我尝试使用 url > http://localhost:8080/greetingservice/swagger-ui.html 访问类似于文档中描述的文档时,出现 404 错误

但是我使用 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

关于java - SpringFox Swagger 与 Springboot 应用程序集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38214008/

相关文章:

java - 使用 Spring MVC 中的属性文件更新默认区域设置值

spring - 我可以从没有注释 componentscan,autoconfiguration,configuration,springbootapplication 的 spring boot 应用程序开始吗?

java - 从文本文件中删除特定行

java - 为什么这是一个无法访问的语句?

java - 防止 WebLogic 服务器上的 XSD 的外部引用

java - 更改 Spring Boot/Netty 中的错误日志记录

javascript - 如何使用JavaScript将文件作为多部分文件上传到后端?

java - 设置 null 而不出现 NullPointerException

java - 如何为布局的宽度和高度设置动画?

java - 带有 JPARepository (MySQL) 的 Spring Boot 应用程序无法启动