在springboot 2 项目中使用Swagger2生成在线文档,项目启动时,出现大量类似以下日志
出现这种日志的主要原因是,两个不同的类 使用@ApiOperation注解,且不同的类中存在相同的方法名(enable)导致,如
// 类1,有以下代码
@RestController
@RequestMapping("/api/c1")
@Api(tags = "接口1")
public class C1Controller {
@ApiOperation(value = "启用记录", notes = "")
@ApiImplicitParam(paramType = "path", name = "id", value = "记录ID", required = true)
@PutMapping("/enable/{id}")
public HA<?> enable(@PathVariable Integer id){
try {
service.updateStatus(id);
} catch (Exception e) {
e.printStackTrace();
}
}
}
// 类2,也有以下代码
@RestController
@RequestMapping("/api/c2")
@Api(tags = "接口2")
public class C2Controller {
@ApiOperation(value = "启用记录", notes = "")
@ApiImplicitParam(paramType = "path", name = "id", value = "记录ID", required = true)
@PutMapping("/enable/{id}")
public HA<?> enable(@PathVariable Integer id){
try {
service.updateStatussssss(id);
} catch (Exception e) {
e.printStackTrace();
}
}
}
这时只要将类2或类1其中一个类的enable()方法名变更即可,只需修改方法名称。如,将类2的enable(),修改为enable2(),重启即可
// 类1,有以下代码
@RestController
@RequestMapping("/api/c1")
@Api(tags = "接口1")
public class C1Controller {
@ApiOperation(value = "启用记录", notes = "")
@ApiImplicitParam(paramType = "path", name = "id", value = "记录ID", required = true)
@PutMapping("/enable/{id}")
public HA<?> enable(@PathVariable Integer id){
try {
service.updateStatus(id);
} catch (Exception e) {
e.printStackTrace();
}
}
}
// 类2,也有以下代码
@RestController
@RequestMapping("/api/c2")
@Api(tags = "接口2")
public class C2Controller {
@ApiOperation(value = "启用记录", notes = "")
@ApiImplicitParam(paramType = "path", name = "id", value = "记录ID", required = true)
@PutMapping("/enable/{id}")
public HA<?> enable2(@PathVariable Integer id){
try {
service.updateStatussssss(id);
} catch (Exception e) {
e.printStackTrace();
}
}
}