首页 文章

Swagger endpoints 无法访问

提问于
浏览
0

我有一个spring mvc项目,它使用gradle来构建项目 .

我在这个项目中使用了here描述的步骤 .

build.gradle文件具有swagger的以下条目:

compile (libraries.swagger){
    exclude group:'org.slf4j', module:'slf4j-log4j12'
    exclude group:'org.slf4j', module:'slf4j-api'
    exclude group:'junit', module:'junit'
  }

swagger的配置在项目build.gradle中完成,如下所示:

swagger: "com.knappsack:swagger4spring-web:0.3.3"

我的文档终点控制器是:

import com.knappsack.swagger4springweb.controller.ApiDocumentationController;
import com.wordnik.swagger.model.ApiInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * This is an example of how you might extend the ApiDocumentationController in order to set your
 * own RequestMapping (instead of the default "/api") among other possibilities.  Going this route,
 * you do not necessarily have to define the controller in your servlet context.
 */
@Controller
@RequestMapping(value = "/documentation")
public class SwaggerDocumentationController extends ApiDocumentationController {

  public SwaggerDocumentationController() {
    setBaseControllerPackage("com.controller");
    setBaseModelPackage("com.domain");
    setApiVersion("v1");

    ApiInfo apiInfo = new ApiInfo("swagger",
        "This is a basic web app for demonstrating swagger",
        "http://localhost:9999/terms", "http://localhost:9999/contact", "MIT",
        "http://opensource.org/licenses/MIT");
    setApiInfo(apiInfo);
  }

  @RequestMapping(value = "/", method = RequestMethod.GET)
  public String documentation() {
    return "documentation";
  }
}

然后我尝试访问 endpoints 以获取文档: http://localhost:9999/myApp/documentation/test

test 是控制器内部提到的映射,如下所示:

@Api(value = "test",
    description = "A test controller to see if the services are up and running.")
@RequestMapping(value = {"/test"}, method = {RequestMethod.GET})

访问上面的文档URL时,我收到404未找到错误 . 我错过了什么吗?

如果需要更多信息,请告诉我 .

请帮忙 !!

1 回答

相关问题