服务启动创建代理对象之前, 确实检查了stub类中是否存在公共的有参构造器,而且校验通过。
但是创建代理类的时候,却没有在外面包裹stub,也就是说没有调用到stub的有参构造器中
@DubboService(stub = "com.atguihgu.boot.dubbo.api.stub.IOrderServiceStub")
public class IOrderServiceImpl implements IOrderService {
@Override
public PersonPojo getPersonByName(String name) {
if("kobe".equals(name)){
return new PersonPojo("kobe","male",40);
}else if ("james".equals(name)){
return new PersonPojo("james","male",38);
}else{
throw new RuntimeException("没发现数据:name="+name) ;
}
}
}
@Slf4j
public class IOrderServiceStub implements IOrderService {
private final IOrderService iOrderService;
//包装类:必须添加“有参构造器”, 且需要pubic★
public IOrderServiceStub(IOrderService iOrderService){
this.iOrderService = iOrderService; // debug断点,没有进来这里,也就没有成功创建stub
}
@Override
public PersonPojo getPersonByName(String name) {
log.info("【IOrderServiceStub】开启,aop拦截-开始");
try{
if("XXX".equals(name)){
log.info("IOrderServiceStub,aop拦截");
return new PersonPojo("秘密人员","性别保密",999);
}else{
return iOrderService.getPersonByName(name);
}
}finally {
log.info("【IOrderServiceStub】开启,aop拦截-结束");
}
}
}
要客户端的配置里stub: