Java SpringMVC项目的招摇过市
关于在Spring MVC中集成Swagger: Swagger没有显示Java SpringMVC项目的招摇过市,java,spring-mvc,swagger,Java,Spring Mvc,Swagger,关于在Spring MVC中集成Swagger: Swagger没有显示@RequestMapping 在我的SpringMVCERESTWebService应用程序中,我有一个登录控制器和一个学生控制器。 我刚刚配置了Swagger来生成RESTAPI文档。 参考: 问题:但是,Swagger仅显示类级别的路径,我猜它甚至没有显示类级别的@RequestMapping忽略方法级别的映射。有什么原因吗 @Controller @RequestMapping(value = "/login") p
@RequestMapping
在我的SpringMVCERESTWebService应用程序中,我有一个登录控制器和一个学生控制器。
我刚刚配置了Swagger来生成RESTAPI文档。
参考:
问题:但是,Swagger仅显示类级别的路径,我猜它甚至没有显示类级别的@RequestMapping
忽略方法级别的映射。有什么原因吗
@Controller
@RequestMapping(value = "/login")
public class LoginController {
@RestController
@RequestMapping(value = "/students/")
public class StudentController {
@RequestMapping(value = "{departmentID}", method = RequestMethod.GET)
public MyResult getStudents(@PathVariable String departmentID) {
// code
}
@RequestMapping(value = "student", method = RequestMethod.GET)
public MyResult getStudentInfo(
@RequestParam(value = "studentID") String studentID,
@RequestParam(value = "studentName") String studentName) {
//code
}
@RequestMapping(value = "student", method = RequestMethod.POST)
public ResponseEntity<Student> updateStudentInfo(@RequestBody Student student) {
//code
}
输出:
http://localhost:8080/studentapplication/api-docs
{
apiVersion: "1.0",
swaggerVersion: "1.2",
apis: [
{
path: "/default/login-controller",
description: "Login Controller"
},
{
path: "/default/student-controller",
description: "Student Controller"
}
],
info: {
title: "Student API",
description: "API for Student",
termsOfServiceUrl: "StudentApp API terms of service",
contact: "abc@xyz.com",
license: "sometext",
licenseUrl: "License URL"
}
}
更新:
您还需要spring配置XML文件中的以下配置,如中所述
无论现在看到的输出是什么,我们都不会在这个
JSON
输出中看到招摇过市的UI和GET/POST/PUT
方法级映射。那很好。它只显示类级别的路径
要查看带有GET/POST/PUT
方法级映射和URL的实际招摇过市UI,我们需要
要下载此处提供的SwaggerUI
:
然后导航到此index.html
文件:swagger-ui-master\swagger-ui-master\dist\index.html
在这里,将源JSON URL编辑为您的应用程序api文档URL:
即:
现在你看到了一切
我离…只有一步之遥。检查输出,然后确定。我不知道springmvc的开发人员在这方面的表现如何,所以如果您没有及时得到回复,我建议您在他们的存储库中打开这个问题。感谢您的建议,@webron,谢谢you@webron我解决了这个问题,并张贴为answer@spiderman如果使用注释方法而没有spring配置XML,如何配置这些?
http://localhost:8080/studentapplication/api-docs
{
apiVersion: "1.0",
swaggerVersion: "1.2",
apis: [
{
path: "/default/login-controller",
description: "Login Controller"
},
{
path: "/default/student-controller",
description: "Student Controller"
}
],
info: {
title: "Student API",
description: "API for Student",
termsOfServiceUrl: "StudentApp API terms of service",
contact: "abc@xyz.com",
license: "sometext",
licenseUrl: "License URL"
}
}
<!-- to enable the default documentation controller-->
<context:component-scan base-package="com.mangofactory.swagger.controllers"/>
<!-- to pick up the bundled spring configuration-->
<context:component-scan base-package="com.mangofactory.swagger.configuration"/>
<!-- Direct static mappings -->
<mvc:resources mapping="*.html" location="/, classpath:/swagger-ui"/>
<!-- Serve static content-->
<mvc:default-servlet-handler/>
$(function () {
window.swaggerUi = new SwaggerUi({
url: "studentapplication/api-docs",
dom_id: "swagger-ui-container",
supportedSubmitMethods: ['get', 'post', 'put', 'delete'],