【问题标题】:SpringFox Swagger integration with Springboot appSpringFox Swagger 与 Springboot 应用程序集成
【发布时间】:2016-07-05 22:45:03
【问题描述】:

我按照link(直到步骤 5.1)中列出的步骤来集成 swagger 文档。下面是我的控制器类的样子。当我尝试使用 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));
    }
}

【问题讨论】:

    标签: java spring spring-boot swagger springfox


    【解决方案1】:

    当我尝试访问类似于以下内容的文档时出现 404 错误 使用 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

    【讨论】:

      猜你喜欢
      • 2019-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-18
      • 1970-01-01
      • 2019-05-06
      • 2019-07-19
      相关资源
      最近更新 更多