fegin 接口
package com.xxx.api;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@FeignClient(value = "Test", contextId = "Test-XxxServiceI")
@RequestMapping(path = "/Test")
public interface XxxServiceI {
@PostMapping(path = "/add/v1")
String add(
@Parameter(name = "参数") @RequestBody Object object);
}
controller 接口
package com.xxx.controller;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RestController;
@RestController("XxxController")
@RequiredArgsConstructor
public class XxxController implements XxxfServiceI {
private final XxxService xxxService;
@Override
public String createStoreCommodityGroup(Object object) {
String id = xxxService.add(object);
return id;
}
}
启动类
@EnableFeignClients(basePackages = {"com.xxx"})
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
异常信息
Caused by: java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'com.aliyun.bizworks.operation.client.commodity.api.OperationCommodityServiceI' method
com.aliyun.bizworks.operation.client.commodity.api.OperationCommodityServiceI#createCommodity(OperationCommodityCreateDTO)
to {POST /Operation/commodity/createCommodity/v1}: There is already 'OperationCommodityServiceController' bean method
异常原因
在启动类上的 @EnableFeignClients(basePackages = {"com.xxx"})注解,扫描到了controller层和api层,因为controller层实现了api接口,所以会扫描到两次相同的路径,
解决办法,扫描@EnableFeignClients的包路径详细到fegin接口的包下
@EnableFeignClients(basePackages = {"com.xxx.api"})
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
|