使用Swagger2时启动控制台输出大量 Generating unique operation named: ***

在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();
		}
	}
}

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值