spring引导将接口作为bean实现
当我使用mybatis multi-datasource配置spring boot 1.5时,SimsCardTypeController中构造函数的经典错误参数0需要一个bean,但找到了2个:aImpl,一个come out。 以下是相关课程:spring引导将接口作为bean实现,spring,spring-boot,Spring,Spring Boot,当我使用mybatis multi-datasource配置spring boot 1.5时,SimsCardTypeController中构造函数的经典错误参数0需要一个bean,但找到了2个:aImpl,一个come out。 以下是相关课程: @RestController @RequestMapping("/xx") public class SimsCardTypeController extends RestBase { private A simsCardTypeServi
@RestController
@RequestMapping("/xx")
public class SimsCardTypeController extends RestBase {
private A simsCardTypeService;
private HttpServletRequest request;
@Autowired
public SimsCardTypeController(A simsCardTypeService, HttpServletRequest request) {
this.simsCardTypeService = simsCardTypeService;
this.request = request;
}
..
}
@Component
public class RestBase {}
interface A{}
@Service
class AImpl implements A{}
我不知道任何可能的配置引导Spring将A作为bean。如何调试这种情况?这是mybatis扫描的问题,mybatis将接口转换为映射器。我分享了调试类似问题的技巧: 1.将奇怪的接口A限定为Spring要求的bean
@Autowired
public SimsCardTypeController(@Qualifier(value="A")A simsCardTypeService, HttpServletRequest request){}
二,。在主体中添加断点,您可以看到simsCardTypeService的确切含义。在我的例子中,它类似于xxMapper,所以我可以将它与mybatis扫描联系起来
谢谢你能发布你的完整代码和异常吗?我发布了相关的类和异常。有两个类实现了接口A吗?不,我已经检查了这种可能性,异常提到A是一个bean。你能在github上发布你的完整项目并共享d链接吗?