dubbo在controller中reference注解为空的问题深度解析

轻量开源版 IDEA:Java/Spring Boot 开发者的精准裁剪指南 IDEA 作为主流 Java 集成开发环境,其开箱即用的全栈能力常带来冗余负载。理解其插件机制、索引原理与 JVM 运行模型,是实现高效开发的前提。通过可复现的配置策略——如插件白名单、索引范围限定、vmoptions 反常识调优——开发者能在不牺牲 Spring Boot 深度支持(如配置跳转、MyBatis 校验、代理对象调试)的前提下,显著降低启动延迟与内存占用。这种‘功能密度提升’而非简单减法,契合现代 Java 工程对确定性、可维护性与团队协同的要求,尤其适用于 Spring Boot 四层架构落 阅读详情

dubbo注解的使用

使用非常简单,下面贴出关键部分

//provider的配置文件
<?xml version="1.0" encoding="UTF-8"?>  
<beans xmlns="http://www.springframework.org/schema/beans"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"  
    xsi:schemaLocation="http://www.springframework.org/schema/beans          
    http://www.springframework.org/schema/beans/spring-beans.xsd          
    http://code.alibabatech.com/schema/dubbo          
    http://code.alibabatech.com/schema/dubbo/dubbo.xsd">  
    <!-- 提供方应用信息,用于计算依赖关系 -->  
    <dubbo:application name="provider-app"  />  
    <!-- 使用zookeeper注册中心暴露服务地址 -->  
    <dubbo:registry protocol="zookeeper" address="127.0.0.1:2181" />
    <!-- 用dubbo协议在20880端口暴露服务 -->  
    <dubbo:protocol name="dubbo" port="20880" />

    <dubbo:annotation package="com.i.springboot.controller" />
</beans>
//服务接口类
@com.alibaba.dubbo.config.annotation.Service
public class PostService {
    ………………省略……………………
}

//consumer端配置
<?xml version="1.0" encoding="UTF-8"?>  
<beans xmlns="http://www.springframework.org/schema/beans"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"  
    xsi:schemaLocation="http://www.springframework.org/schema/beans          
    http://www.springframework.org/schema/beans/spring-beans.xsd          
    http://code.alibabatech.com/schema/dubbo          
    http://code.alibabatech.com/schema/dubbo/dubbo.xsd">  
    <!-- 消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样 -->  
    <dubbo:application name="consumer-app"/>  
    <dubbo:registry address="zookeeper://127.0.0.1:2181" />
    <dubbo:annotation package="com.i.springboot.controller"/>
</beans>  

//服务引用
@Controller
@RequestMapping("/post")
@SessionAttributes("currentUser")
public class PostController {
    //注解使用dubbo服务端服务
    @Reference
    PostService postService;
    ……………省略……………
}

以上如果只是用spring的容器,而不使用springmvc进行结合使用时是不会出现引用为空的问题的;但是如果不了解spring和springmvc加载配置文件和初始化bean的流程,则极有可能出现postService为Null的情况,错误配置如下

我src/main/resources下面有spring-consumer.xml、spring-mvc.xm两个配置文件,spring-mvc.xml和web.xml配置部分如下

<?xml version="1.0" encoding="UTF-8"?>    
<beans xmlns="http://www.springframework.org/schema/beans"   
    xmlns:context="http://www.springframework.org/schema/context"   
    xmlns:mvc="http://www.springframework.org/schema/mvc"  
    xmlns:p="http://www.springframework.org/schema/p"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
    xsi:schemaLocation="http://www.springframework.org/schema/beans   
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
    http://www.springframework.org/schema/context  
    http://www.springframework.org/schema/context/spring-context.xsd  
    http://www.springframework.org/schema/mvc   
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> 

    <!-- 自动扫描controller包下的所有类,使其认为spring mvc的控制器 -->
    <context:component-scan base-package="com.i.springboot.controller" />
    ……………………省略…………………………
</beans>

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
  <display-name>Archetype Created Web Application</display-name>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        classpath*:/spring-*.xml
    </param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>

    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring-mvc.xml</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>
</web-app>

初步一看完全没有问题,spring启动的时候会扫描controller包,然后初始化我的postService服务类,一切想的都是那么美好,程序一运行,一个大大的空指针异常抛出,然后网上、qq上一堆乱问,终不得解,生无可恋,下面一步步解决问题
开始之前提出如下疑问

  1. spring是什么时候跟dubbo勾搭在一起的
  2. 为什么PostService上面加上dubbo的Service注解,服务类就会被加载
  3. 为什么dubbo官方文件所说的通过Reference引用服务却为NULL

dubbo和spring结合

到底dubbo是怎么和spring组合的呢,先看如下

<beans xmlns="http://www.springframework.org/schema/beans"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"  
    xsi:schemaLocation="http://www.springframework.org/schema/beans          
    http://www.springframework.org/schema/beans/spring-beans.xsd          

    http://code.alibabatech.com/schema/dubbo          
    http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

注意到xmlns:dubbo=”http://code.alibabatech.com/schema/dubbo”了吗,仔细想想spring怎么解析xml配置文件的,NamespaceHandler、NamespaceHandlerSupport、BeanDefinitionParser,spring提供的一种SPI规范,dubbo定义了自己的schema、namespacehandler、beandefinitionparser

/**
 * DubboNamespaceHandler
 * 
 * @author william.liangf
 * @export
 */
public class DubboNamespaceHandler extends NamespaceHandlerSupport {

    static {
        Version.checkDuplicate(DubboNamespaceHandler.class);
    }

    public void init() {
        registerBeanDefinitionParser("application", new DubboBeanDefinitionParser(ApplicationConfig.class, true));
        registerBeanDefinitionParser("module", new DubboBeanDefinitionParser(ModuleConfig.class, true));
        registerBeanDefinitionParser("registry", new DubboBeanDefinitionParser(RegistryConfig.class, true));
        registerBeanDefinitionParser("monitor", new DubboBeanDefinitionParser(MonitorConfig.class, true));
        registerBeanDefinitionParser("provider", new DubboBeanDefinitionParser(ProviderConfig.class, true));
        registerBeanDefinitionParser("consumer", new DubboBeanDefinitionParser(ConsumerConfig.class, true));
        registerBeanDefinitionParser("protocol", new DubboBeanDefinitionParser(ProtocolConfig.class, true));
        registerBeanDefinitionParser("service", new DubboBeanDefinitionParser(ServiceBean.class, true));
        registerBeanDefinitionParser("reference", new DubboBeanDefinitionParser(ReferenceBean.class, false));
        registerBeanDefinitionParser("annotation", new DubboBeanDefinitionParser(AnnotationBean.class, true));
    }

}

结合
DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions,xml配置文件就这样开始解析,具体不做描述,主要看dubbo是如何搭上spring的车的,解析过程咱们重点看AnnotationsBean的解析,也就是dubbo的DubboBeanDefinitionParser类

dubbo的service、reference是如何初始化的

DubboBeanDefinitionParser的parse方法被调用后,dubbo定义的几个大的标签application、registry、provider、consumer、annotation等都会被初始化,并包装成RootBeanDefinition在spring的bean容器中

@SuppressWarnings("unchecked")
    private static BeanDefinition parse(Element element, ParserContext parserContext, Class<?> beanClass, boolean required) {
        RootBeanDefinition beanDefinition = new RootBeanDefinition();
        beanDefinition.setBeanClass(beanClass);
        beanDefinition.setLazyInit(false);
       ……………………………省略具体解析代码…………………………………
        return beanDefinition;
    }

重点看annotation实例化过程,也是dubbo注解的关键,进入此类,看到一长串的类

public class AnnotationBean extends AbstractConfig implements DisposableBean, BeanFactoryPostProcessor, BeanPostProcessor, ApplicationContextAware {

不得不提下spring的processer和aware两个SPI点,设计的非常巧妙,完全符合设计六大原则之一的开闭原则

//任选一种都支持process和aware两种方式
<context:annotation-config/>
<context:component-scan base-package="xx.xx.xx" />

dubbo充分利用了spring提供的机制进行service的初始化和reference的实例化的

service的实例化过程

第一步

public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
            throws BeansException {
        if (annotationPackage == null || annotationPackage.length() == 0) {
            return;
        }
        if (beanFactory instanceof BeanDefinitionRegistry) {
            try {
                // init scanner
                Class<?> scannerClass = ReflectUtils.forName("org.springframework.context.annotation.ClassPathBeanDefinitionScanner");
                Object scanner = scannerClass.getConstructor(new Class<?>[] {BeanDefinitionRegistry.class, boolean.class}).newInstance(new Object[] {(BeanDefinitionRegistry) beanFactory, true});
                // add filter
                Class<?> filterClass = ReflectUtils.forName("org.springframework.core.type.filter.AnnotationTypeFilter");
                Object filter = filterClass.getConstructor(Class.class).newInstance(Service.class);
                Method addIncludeFilter = scannerClass.getMethod("addIncludeFilter", ReflectUtils.forName("org.springframework.core.type.filter.TypeFilter"));
                addIncludeFilter.invoke(scanner, filter);
                // scan packages
                String[] packages = Constants.COMMA_SPLIT_PATTERN.split(annotationPackage);
                Method scan = scannerClass.getMethod("scan", new Class<?>[]{String[].class});
                scan.invoke(scanner, new Object[] {packages});
            } catch (Throwable e) {
                // spring 2.0
            }
        }
    }

实例化一个ClassPathBeanDefinitionScanner类,通过反射实现有参构造的初始化,将注册bean的(BeanDefinitionRegistry) beanFactory作为参数传递给实例,最后反射调用scanner的scan方法,将service注解的实例增加至spring容器中
第二步

public Object postProcessAfterInitialization(Object bean, String beanName)
            throws BeansException {
        //判断是不是dubbo需要处理的bean类,如果是则继续进行处理,不是则不做任何处理
        if (! isMatchPackage(bean)) {
            return bean;
        }
        Service service = bean.getClass().getAnnotation(Service.class);
        if (service != null) {
            ServiceBean<Object> serviceConfig = new ServiceBean<Object>(service);
            if (void.class.equals(service.interfaceClass())
                    && "".equals(service.interfaceName())) {
                if (bean.getClass().getInterfaces().length > 0) {
                    serviceConfig.setInterface(bean.getClass().getInterfaces()[0]);
                } else {
                    throw new IllegalStateException("Failed to export remote service class " + bean.getClass().getName() + ", cause: The @Service undefined interfaceClass or interfaceName, and the service class unimplemented any interfaces.");
                }
            }
            if (applicationContext != null) {
                serviceConfig.setApplicationContext(applicationContext);
                if (service.registry() != null && service.registry().length > 0) {
                    List<RegistryConfig> registryConfigs = new ArrayList<RegistryConfig>();
                    for (String registryId : service.registry()) {
                        if (registryId != null && registryId.length() > 0) {
                            registryConfigs.add((RegistryConfig)applicationContext.getBean(registryId, RegistryConfig.class));
                        }
                    }
                    serviceConfig.setRegistries(registryConfigs);
                }
                if (service.provider() != null && service.provider().length() > 0) {
                    serviceConfig.setProvider((ProviderConfig)applicationContext.getBean(service.provider(),ProviderConfig.class));
                }
                if (service.monitor() != null && service.monitor().length() > 0) {
                    serviceConfig.setMonitor((MonitorConfig)applicationContext.getBean(service.monitor(), MonitorConfig.class));
                }
                if (service.application() != null && service.application().length() > 0) {
                    serviceConfig.setApplication((ApplicationConfig)applicationContext.getBean(service.application(), ApplicationConfig.class));
                }
                if (service.module() != null && service.module().length() > 0) {
                    serviceConfig.setModule((ModuleConfig)applicationContext.getBean(service.module(), ModuleConfig.class));
                }
                if (service.provider() != null && service.provider().length() > 0) {
                    serviceConfig.setProvider((ProviderConfig)applicationContext.getBean(service.provider(), ProviderConfig.class));
                } else {

                }
                if (service.protocol() != null && service.protocol().length > 0) {
                    List<ProtocolConfig> protocolConfigs = new ArrayList<ProtocolConfig>();
                    for (String protocolId : service.registry()) {
                        if (protocolId != null && protocolId.length() > 0) {
                            protocolConfigs.add((ProtocolConfig)applicationContext.getBean(protocolId, ProtocolConfig.class));
                        }
                    }
                    serviceConfig.setProtocols(protocolConfigs);
                }
                try {
                    serviceConfig.afterPropertiesSet();
                } catch (RuntimeException e) {
                    throw (RuntimeException) e;
                } catch (Exception e) {
                    throw new IllegalStateException(e.getMessage(), e);
                }
            }
            //
            serviceConfig.setRef(bean);
            serviceConfigs.add(serviceConfig);
            //通过注册中心暴露dubbo的服务
            serviceConfig.export();
        }
        //返还spring容器,有点类似于装饰
        return bean;
    }

至此,dubbo通过service注解实现spring容器管理完毕

reference实例过程

reference和service最大的不同是,reference注解生成的实例就没有交给spring容器去管理,而只是作为spring管理bean的一个属性赋值操作,通过反射来实现,代码如下

public Object postProcessBeforeInitialization(Object bean, String beanName)
            throws BeansException {
        //和service一样
        if (! isMatchPackage(bean)) {
            return bean;
        }
        Method[] methods = bean.getClass().getMethods();
        for (Method method : methods) {
            String name = method.getName();
            if (name.length() > 3 && name.startsWith("set")
                    && method.getParameterTypes().length == 1
                    && Modifier.isPublic(method.getModifiers())
                    && ! Modifier.isStatic(method.getModifiers())) {
                try {
                    Reference reference = method.getAnnotation(Reference.class);
                    if (reference != null) {
                        Object value = refer(reference, method.getParameterTypes()[0]);
                        if (value != null) {
                            method.invoke(bean, new Object[] {  });
                        }
                    }
                } catch (Throwable e) {
                    logger.error("Failed to init remote service reference at method " + name + " in class " + bean.getClass().getName() + ", cause: " + e.getMessage(), e);
                }
            }
        }
        Field[] fields = bean.getClass().getDeclaredFields();
        for (Field field : fields) {
            try {
                if (! field.isAccessible()) {
                    field.setAccessible(true);
                }
                //本项目使用的是PostController,field就是controller中的postService,refer方法则是通过连接注册中心,检测服务是否存在,当然如果配置中check为false就不会现在进行检测
                Reference reference = field.getAnnotation(Reference.class);
                if (reference != null) {
                    //refer方法有兴趣可以自己看,牵扯到zk和netty
                    Object value = refer(reference, field.getType());
                    if (value != null) {
                        field.set(bean, value);
                    }
                }
            } catch (Throwable e) {
                logger.error("Failed to init remote service reference at filed " + field.getName() + " in class " + bean.getClass().getName() + ", cause: " + e.getMessage(), e);
            }
        }
        //将controller中有reference标示的字段赋值后返回,并没有将字段类实例注入spring容器,确实也没有必要
        return bean;
    }

    private Object refer(Reference reference, Class<?> referenceClass) { //method.getParameterTypes()[0]
        String interfaceName;
        if (! "".equals(reference.interfaceName())) {
            interfaceName = reference.interfaceName();
        ……………………省略……………………
        return referenceConfig.get();
    }

至此reference标注的实例也初始化完成,service和referece返回的都是dubbo的代理类com.alibaba.dubbo.common.bytecode.Proxy,用到了jdk的Proxy、InvocationHandler来生成代理类(没有javassist的情况),再次声明,reference标注的对象不会被spring容器管理,是无法通过factory.getBean获取的

Null出现的原因

首先得知道spring容器初始化过程

public class ContextLoaderListener extends ContextLoader implements ServletContextListener

/**
 * Initialize the root web application context.
 */
@Override
public void contextInitialized(ServletContextEvent event) {
    initWebApplicationContext(event.getServletContext());
}

我配置了监听,会读取spring-*.xml配置文件,会初始化一个xmlwebapplicationcontext也就是应用的rootContext顶级容器,这个容器在serverletcontext上下文中,等监听初始化完毕后,我们配置的dispatcherservlet开始初始化

/**
     * Overridden method of {@link HttpServletBean}, invoked after any bean properties
     * have been set. Creates this servlet's WebApplicationContext.
     */
    @Override
    protected final void initServletBean() throws ServletException {
        try {
            //初始化mvc的容器
            this.webApplicationContext = initWebApplicationContext();
            initFrameworkServlet();
        }
    }

protected WebApplicationContext initWebApplicationContext() {
        //获取监听初始化的顶级容器
        WebApplicationContext rootContext =
                WebApplicationContextUtils.getWebApplicationContext(getServletContext());
        WebApplicationContext wac = null;

        if (this.webApplicationContext != null) {
            // A context instance was injected at construction time -> use it
            wac = this.webApplicationContext;
            if (wac instanceof ConfigurableWebApplicationContext) {
                ConfigurableWebApplicationContext cwac = (ConfigurableWebApplicationContext) wac;
                if (!cwac.isActive()) {
                    // The context has not yet been refreshed -> provide services such as
                    // setting the parent context, setting the application context id, etc
                    if (cwac.getParent() == null) {
                        // The context instance was injected without an explicit parent -> set
                        // the root application context (if any; may be null) as the parent
                        cwac.setParent(rootContext);
                    }
                    configureAndRefreshWebApplicationContext(cwac);
                }
            }
        }
        if (wac == null) {
            // No context instance was injected at construction time -> see if one
            // has been registered in the servlet context. If one exists, it is assumed
            // that the parent context (if any) has already been set and that the
            // user has performed any initialization such as setting the context id
            wac = findWebApplicationContext();
        }
        if (wac == null) {
            // No context instance is defined for this servlet -> create a local one
            //初始化XmlWebApplicationContext开始,它会读取配置文件spring-mvc.xml
            wac = createWebApplicationContext(rootContext);
        }

        if (!this.refreshEventReceived) {
            // Either the context is not a ConfigurableApplicationContext with refresh
            // support or the context injected at construction time had already been
            // refreshed -> trigger initial onRefresh manually here.
            onRefresh(wac);
        }

        if (this.publishContext) {
            // Publish the context as a servlet context attribute.
            String attrName = getServletContextAttributeName();
            //将mvc容器放入servletcontext上下文中
            getServletContext().setAttribute(attrName, wac);
            if (this.logger.isDebugEnabled()) {
                this.logger.debug("Published WebApplicationContext of servlet '" + getServletName() +
                        "' as ServletContext attribute with name [" + attrName + "]");
            }
        }

        return wac;
    }

监听初始化的容器读取了所有的配置文件,并初始化了controller类,同时将dubbo注解reference的实例set给了controller,而后servlet初始化过程中又再一次读取了spring-mvc.xml配置文件,同时也对controller进行了初始化,但是与顶级容器初始化不同的是,它没有加载dubbo实现的DubboNamespaceHandler,也就是说reference实例化的过程都没有进行,因此在mvc容器中的controller是没有注入reference标注的实例的,因此出现NULL的情况

总结

遇到这样的问题是一种幸运,也是一种不幸,幸运的是通过debug看源码的过程增加了对spring的了解以及框架的优秀设计,不幸的是对于spring一些细节的地方还不够了解;遇到问题不放弃、不抛弃,加油

生产问题:@Reference注入为空 线上发生事故了 有一次我负责的系统和收银系统同时上线一波(用的是Dubbo)。然后很神奇的事情发生了,收银系统用@Reference注解注入我的接口,然后这个接口的实现类居然为空。 其实我们当时没排查出来是什么原因? 重启了一下就好了,毕竟重启大法好。 但本着不能给用户充钱的路上造成阻碍,还是要排查一波这个代理对象为空是如何造成的。 线上dubbo的版本为2.8.9,注意包名是(com.alibaba) 为了方便大家理解我说的内容,简单说一下RPC框架的执行流程。 Server将服务信息注册到Regi. 阅读详情

相关推荐

实用电路精讲系列---仪表放大器

摘要 仪表放大器通过三级运放架构实现高共模抑制比(CMRR>100dB)和精密差分放大,其核心是第一级同相运放提供高输入阻抗和可调增益(G=1+2R/RG),第二级差分运放消除共模干扰。具有低失调(≤50μV)、低温漂(≤0.6μV/℃)特性,广泛应用于智能断路器电流监测、ECG心电信号放大等场景。典型电路采用LTC1049运放,通过匹配电阻网络实现199倍差分增益,结合输出缓冲确保信号稳定性。设计时需注意输入共模电压范围限制和增益电阻精度,优选集成IC(如AD620、INA128)以规避分立元件匹配

weixin_40590799的博客 2069

(maven)关于dubbo @Reference注入为null问题,本人已解决

关于dubbo @Reference注入为null问题,本人已解决 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 我也是第一次写这个,有误地方请指出,我也是一个爱学习的好公民,哈哈 dubbo 我也是今天开始使用的,然后就遇到@Reference为空, 然后找了很多博客,大多数都是花里胡哨的,我在这里也不讲源码了,看不懂,直接说解决方案...

star_sky_zbs的博客 7803

oVirt 4.4.10超详细安装指南:从零搭建企业级虚拟化环境(附常见错误排查)

本文提供了oVirt 4.4.10企业级虚拟化平台的超详细安装指南,涵盖环境规划、系统准备、Engine安装配置、计算节点部署、存储系统集成及高级运维技巧。通过实战操作手册和常见错误排查方法,帮助用户从零搭建稳定高效的虚拟化环境,特别适合企业IT管理员参考实施。

wasm7browser的博客 347

【dubbo】reference注入为null的问题排查

【dubbo】reference注入为null的问题排查,服务既是提供者也是消费者

csdn_halon的博客 1815

Realtek 10GbE芯片组解析:低成本高速网络方案

10GbE(万兆以太网)技术通过提升网络带宽,显著改善了数据传输效率,成为现代网络架构的核心组件。其工作原理基于高速串行通信协议,通过优化信号处理和编码技术实现低延迟、高吞吐量。在技术价值上,10GbE不仅满足数据中心和企业网络的高需求,还逐步渗透到消费级市场,推动家庭和小型企业的网络升级。应用场景包括NAS存储、视频编辑工作站和云服务接入等。Realtek最新发布的RTL8127、RTL8159和RTL8261C芯片组,以低功耗和低成本优势,进一步降低了10GbE的普及门槛。这些芯片支持PCIe Gen4

weixin_36427956的博客 578

vscode运行.ipynb代码时提示需要安装ipykernel包的解决办法

此文目的是为了记录遇到的一些问题,也希望能帮助到和我一样遇到困难的同学。如需转载,请注明出处。在使用vscode运行.ipynb文件中提示需要安装ipykernel包的提示,在网上查询了很多方法之后也是终于解决了问题。写下这篇博客也希望能帮到大家。

qq_58018041的博客 4万+

Springboot 集成dubbo 解决@Reference 注解为空问题汇总

Springboot 集成dubbo,是目前主流的微服务架构之一,两者在集成过程中经常遇到生产者提供的服务类,在消费者服务里依赖注入时启动报错或者注入为空的情况,今天我分享几种情况产生的原因: 首先在查看问题汇总之前需要先了解Springboot 集成dubbo的各种配置和依赖:参考 一、dubbo的注册中心ZK地址配错,导致启动后依赖注入的对象为空: 1、 错误配置:忘记前缀或者后面的端口号,导致启动时就报错 spring: dubbo: application: nam

nandao158的博客 4407

在ubuntu20.04中安装MATLAB时常见问题及解决方法

   如果你刚装完ubuntu20.04,这时你想要安装MATLAB2021A,在输入命令./install进行安装时,可能会报以下错误:    terminate called after throwing an instance of ‘JailContainerException’ what(): Error: 88: No JRE version parsed from/media/jzx/MATHWORKS_R2021A/sys /java/jre/glnxa64/jre/release   

慕羽★的博客 1万+

Spring4.3整合dubbo纯注解配置以及解决dubbo中@Reference为null的问题

前言 环境为jdk1.8,maven 3.3.3 , tomcat 8,dubbo 2.5.3 接口 public interface IUserService { User selectUser(int id); } 注意User实体需要序列化实现Serializable接口。接口和实体抽出为公共jar包,供服务端和客户端使用。 服务端配置 实现类 package ...

拨开云雾看世界 1万+

从 Service Entry Sheet 按 PO 行项目追溯服务行:PACKNO 与 ESLL 层级解包实战

摘要: SAP MM模块中,外部服务采购的数据结构较为复杂,服务明细并非直接存储在采购订单行项目表EKPO中,而是通过PACKNO关联到服务包表ESLL。本文解析了从采购订单行项目EBELN+EBELP获取服务行号SRVPOS的方法,重点分析了服务包的层级结构(根包、子包SUB_PACKNO),并提供了兼容合同项目的ABAP代码实现。通过EKPO-PACKNO定位根包后,需结合ESUC和ESLL表逐层解析子包,最终获取服务明细数据,解决了服务采购场景下的数据关联难题。(149字)

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 164

【ComfyUI 基础教程】ComfyUI 局部重绘工作流教程

本篇指南将带你了解 ComfyUI 中的局部重绘工作流,并带你完成一个局部重绘的示例,以及遮罩编辑器的使用等。

代码简单说 Vue、JAVA、PHP、Node.js 熟练运用,接口、架构、性能全搞定。 300

学生编程助手选型指南:可理解性、可调试性与上下文连续性

编程助手本质是代码认知增强工具,其核心价值不在于生成速度,而在于是否具备可理解性(生成代码逻辑清晰、注释精准)、可调试性(输出即运行、兼容主流开发环境)和上下文连续性(跨文件/跨阶段语义连贯)。尤其对学生群体而言,这三项指标直接决定学习效率与工程落地能力。结合Keil嵌入式开发、STM32 HAL库调用、Spring Boot课程设计等典型场景,需优先评估工具对中文技术生态(如国产芯片手册、微信小程序API)的支持深度,而非仅关注‘免费’标签。trae在可理解性与硬件上下文识别上优势显著,Copilot则强

weixin_34161032的博客 308

YOLOv5基于深度学习的道路缺陷检测系统

然而,由于长期的自然侵蚀、车辆磨损等因素,道路表面容易出现裂缝、坑洼等缺陷。这些缺陷不仅会影响驾驶舒适性,还可能引发交通事故,尤其是在恶劣天气或夜间行车条件下。随着人工智能技术的快速发展,基于深度学习的道路缺陷检测技术能够在降低人力成本的同时提高检测效率,为道路维护提供了新的解决方案。本项目构建了基于YOLOv5的道路缺陷检测系统,结合PyQt5开发了用户友好的UI界面,具备实时检测和图片分析功能。工具对图片进行标注,生成YOLO格式的标注文件。上传包含道路裂缝或坑洼的图片,系统会标注出缺陷的位置及类别。

YOLO 1076

Java秋招八股之王——拿不到大厂Offer来找我(全文14w字,持续更新)

如果你需要一套八股文,想要一套八股文解决秋招的大部分问题,来看看这篇文章吧~内容包含数据结构、计算机网络、数据库、Redis、消息队列、JavaSE、JVM、JUC、海量数据题目、高并发场景、项目的亮点难点、ssm框架、dubbo框架等等。这是我整个秋招不停面试的总结和反思,最后也是靠它拿到了菜鸟的offer,希望会对后面秋招的朋友起到一些帮助。

qq_40460454的博客 1289

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

Java工程师的AI Agent实战路径:Spring AI与LangChain4j工程落地

Agent是现代AI应用的核心架构范式,其本质是将大语言模型(LLM)与工具调用、记忆管理、检索增强(RAG)等能力编排为可复用的业务组件。理解Agent需从执行生命周期(parse→validate→execute→postProcess)出发,掌握其与传统服务治理、事务控制、可观测性等工程能力的融合逻辑。Java凭借成熟的Spring生态、JVM稳定性及高并发处理能力,在Agent生产化落地中展现出不可替代的技术价值——尤其在订单系统集成RAG、风控引擎多模型仲裁、客服消息Exactly-Once投递等

weixin_32285357的博客 178

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

java八股文极速版

时间和空间的权衡 值越高空间开销小但是增加了查找开销服务于从Key映射到index的Hash算法,在性能和内存的使用上取平衡,实现一个尽量均匀分布的Hash函数,选取16,是通过位运算的方法进行求取的。线程安全:当多线程执行同一段程序的时候,如果发生了和预期结果不一致的情况,就是线程不安全的,如果和预期结果一致就是线程安全的,可以加锁解决(把并行运行的线程变成串行化执行)。1.加锁 利用Synchronized或者ReenTrantLock来对不安全对象进行加锁。

PassionAnytime的博客 381

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

dubbo消费者@Reference引入为null,提供者已注册,消费者未消费

dubbo消费者@Reference引入为null,提供者已注册,消费者未消费 我的错误解决方法: 我遇到的错误是因为@Reference包引入错误,引入的是jdk自带的@Reference,改成alibab的@Reference就好 问题描述: 项目加新功能点之前可以跑通,新加一个功能点之后,不报错也不提示,但前台就是没有数据回显,于是debug查看代码是否携带数据,查看后得到引入的bean为空 解决步骤: 因为之前项目可以跑通,所以也顺带查看了下同包下的controller,比如同个包下的Stemea

mr_zhu_wenxing的博客 2456

Reference注入失败null

服务提供者与消费者的版本不匹配:如果服务提供者和消费者的版本不匹配,注入会失败。服务提供者注册到不同的注册中心:如果服务提供者注册到了不同的注册中心,而消费者只能访问其中一个注册中心,则注入会失败。服务提供者的地址无法访问:如果服务提供者的地址无法访问,则注入会失败。服务提供者的接口发生变化:如果服务提供者的接口发生了变化,而消费者还在使用旧的接口定义,则注入会失败。服务提供者未注册:如果服务提供者未注册到注册中心或者未在本地缓存中发现服务提供者,则注入会失败。check改为false;

hongshipei的博客 515

@Service与@Transactional同时使用,dubbo无法发布

@Service(dubbo的@service)与@Transactional同时使用,dubbo无法发布。 原因: 事务控制的底层原理是为服务提供者类创建代理对象,而默认情况下Spring是基于JDK动态代理方式创建代理对象,而此代理对象的完整类名为com.sun.proxy.$Proxy42(最后两位数字不是固定的),我们在配置中进行包扫描不是com.sun.proxy,导致Dubbo在发布服务前进行包匹配时无法完成匹配,进而没有进行服务的发布。 解决方案: (1)修改applicationContex

qq_35102098的博客 1179

dubbo的@reference注解注入失败,报空指针异常

@reference注解注入失败,报空指针异常

Q_Y521220的博客 1328

dubbo注入失败原因分析解决

INFO 14280 — [nio-8001-exec-1] trationDelegate$BeanPostProcessorChecker : Bean ‘error’ of type [org.springframework.web.servlet.view.InternalResourceView] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-p

m0_46629316的博客 4009

dubbo遇到的坑,dubbo的@Reference注入为null

最近在用dubbo做一个分布式项目,遇到一个大坑,就是但项目带了事务启动AOP的时候, 前端@Reference注入就会为空 开始一直百思不得其解,网上与找到的回答也没用,最后根据网上的不同回答,不断调试,终于解决了,但是不知道原理是什么! 如果有大佬知道的话求解答!! 教程开始: 先在事务的配置文件中加上一个配置 <tx:annotation-driven transaction-manager="txManager" proxy-target-class="true"></tx:an

Linkas的博客 1939
上一篇: 阅读JVM高级特性与最佳实践-1
下一篇: nginx+tomcat+redis+mysql搭建与优化
非洲_bear
博客等级 码龄15年 23粉丝 15原创
评论 21
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值