ServiceComb/CSE的REST接口存在重载的时候报错: OperationId must be unique

Exception in thread "main" java.lang.IllegalStateException: ServiceComb init failed.

at org.apache.servicecomb.core.SCBEngine.init(SCBEngine.java:220)

at org.apache.servicecomb.core.CseApplicationListener.onApplicationEvent(CseApplicationListener.java:81)

at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)

at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)

at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)

at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:393)

at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:347)

at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:883)

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)

at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)

at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:93)

at org.apache.servicecomb.foundation.common.utils.BeanUtils.init(BeanUtils.java:49)

at org.apache.servicecomb.foundation.common.utils.BeanUtils.init(BeanUtils.java:42)

at com.icss.newretail.goods.GoodsMain.main(GoodsMain.java:7)

Caused by: java.lang.Error: OperationId must be unique. com.icss.newretail.api.goods.StockApi:queryGoodsStockByOrg

at org.apache.servicecomb.swagger.generator.core.SwaggerGenerator.scanMethods(SwaggerGenerator.java:281)

at org.apache.servicecomb.swagger.generator.core.SwaggerGenerator.generate(SwaggerGenerator.java:140)

at org.apache.servicecomb.core.definition.schema.AbstractSchemaFactory.generateSwagger(AbstractSchemaFactory.java:102)

at org.apache.servicecomb.core.definition.schema.ProducerSchemaFactory.createSchema(ProducerSchemaFactory.java:115)

at org.apache.servicecomb.core.definition.schema.ProducerSchemaFactory.createSchema(ProducerSchemaFactory.java:54)

at org.apache.servicecomb.core.definition.schema.AbstractSchemaFactory.getOrCreateSchema(AbstractSchemaFactory.java:58)

at org.apache.servicecomb.core.definition.schema.ProducerSchemaFactory.getOrCreateProducerSchema(ProducerSchemaFactory.java:76)

at org.apache.servicecomb.provider.rest.common.RestProducerProvider.init(RestProducerProvider.java:45)

at org.apache.servicecomb.core.provider.producer.ProducerProviderManager.init(ProducerProviderManager.java:51)

at org.apache.servicecomb.core.SCBEngine.doInit(SCBEngine.java:238)

at org.apache.servicecomb.core.SCBEngine.init(SCBEngine.java:209)

... 13 more

 

或者报告path重复

 

Exception in thread "main" java.lang.IllegalStateException: ServiceComb init failed.

at org.apache.servicecomb.core.SCBEngine.init(SCBEngine.java:220)

at org.apache.servicecomb.core.CseApplicationListener.onApplicationEvent(CseApplicationListener.java:81)

at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)

at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)

at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)

at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:393)

at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:347)

at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:883)

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)

at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)

at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:93)

at org.apache.servicecomb.foundation.common.utils.BeanUtils.init(BeanUtils.java:49)

at org.apache.servicecomb.foundation.common.utils.BeanUtils.init(BeanUtils.java:42)

at com.icss.newretail.goods.GoodsMain.main(GoodsMain.java:7)

Caused by: java.lang.Error: Only allowed one default path. com.icss.newretail.api.goods.StockApi:queryGoodsStockByOrg

at org.apache.servicecomb.swagger.generator.core.OperationGenerator.addOperationToSwagger(OperationGenerator.java:424)

at org.apache.servicecomb.swagger.generator.core.SwaggerGenerator.addOperationsToSwagger(SwaggerGenerator.java:289)

at org.apache.servicecomb.swagger.generator.core.SwaggerGenerator.generate(SwaggerGenerator.java:141)

at org.apache.servicecomb.core.definition.schema.AbstractSchemaFactory.generateSwagger(AbstractSchemaFactory.java:102)

at org.apache.servicecomb.core.definition.schema.ProducerSchemaFactory.createSchema(ProducerSchemaFactory.java:115)

at org.apache.servicecomb.core.definition.schema.ProducerSchemaFactory.createSchema(ProducerSchemaFactory.java:54)

at org.apache.servicecomb.core.definition.schema.AbstractSchemaFactory.getOrCreateSchema(AbstractSchemaFactory.java:58)

at org.apache.servicecomb.core.definition.schema.ProducerSchemaFactory.getOrCreateProducerSchema(ProducerSchemaFactory.java:76)

at org.apache.servicecomb.provider.rest.common.RestProducerProvider.init(RestProducerProvider.java:45)

at org.apache.servicecomb.core.provider.producer.ProducerProviderManager.init(ProducerProviderManager.java:51)

at org.apache.servicecomb.core.SCBEngine.doInit(SCBEngine.java:238)

at org.apache.servicecomb.core.SCBEngine.init(SCBEngine.java:209)

... 13 more

 

解决办法:给每个接口制定唯一的operationId和path

1

2

3

4

5

6

7

8

9

10

11

  @GetMapping(path = "queryGoodsStockByOrgAndGoodsId")

  @ApiOperation(nickname = "queryGoodsStockByOrgAndGoodsId", value = "")

  public GoodsStockDTO queryGoodsStockByOrg(@RequestParam(name = "orgId") String orgId,

      @RequestParam(name = "goodsId") String goodsId) {

    return stockService.queryGoodsStockByOrg(orgId, goodsId);

  }

 

  @GetMapping(path = "queryGoodsStockByOrg")

  public List queryGoodsStockByOrg(@RequestParam(name = "orgId") String orgId) {

    return stockService.queryGoodsStockByOrg(orgId);

  }

 

其中ApiOperation指定了唯一ID,GetMapping指定了不同的路径。

你可能感兴趣的:(精品案例)