我有一个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";
}
}
然后我尝试访问文档的端点: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})
访问上面的文档网址时,我发现404找不到错误。我错过了什么吗?
如果需要更多信息,请告诉我。
请帮助!!
答案 0 :(得分:0)
我有用户swagger-springmvc,它的工作正常。您可以通过以下网址尝试 https://github.com/martypitt/swagger-springmvc