dubbo注册中心占位符无法解析问题 (2)

dubbo注册中心占位符无法解析问题

看来,这个问题还得往前找原因。

当我继续往下执行的时候,idea提示断点进入了3.2节的org.springframework.context.support.PropertySourcesPlaceholderConfigurer#postProcessBeanFactory处。

也就是说,在Spring解析占位符之前,dubbo的对象(RegistryConfig)就开始创建并初始化了。

3.4、对象创建时机问题

从前面的分析下来,问题原因算是找到了:

在Spring解析占位符之前,dubbo的对象(RegistryConfig)就开始创建初始化了。导致后面引用的都是未替换占位符的RegistryConfig对象。最终,项目启动才报UnknownHostException: ${zk.address} 异常

再次debug走起,断点停留在RegistryConfig#setAddress方法,看下调用栈:

setAddress:118, RegistryConfig (com.alibaba.dubbo.config), RegistryConfig.java invoke0:-1, NativeMethodAccessorImpl (sun.reflect), NativeMethodAccessorImpl.java invoke:62, NativeMethodAccessorImpl (sun.reflect), NativeMethodAccessorImpl.java invoke:43, DelegatingMethodAccessorImpl (sun.reflect), DelegatingMethodAccessorImpl.java invoke:498, Method (java.lang.reflect), Method.java setValue:332, BeanWrapperImpl$BeanPropertyHandler (org.springframework.beans), BeanWrapperImpl.java processLocalProperty:458, AbstractNestablePropertyAccessor (org.springframework.beans), AbstractNestablePropertyAccessor.java setPropertyValue:278, AbstractNestablePropertyAccessor (org.springframework.beans), AbstractNestablePropertyAccessor.java setPropertyValue:266, AbstractNestablePropertyAccessor (org.springframework.beans), AbstractNestablePropertyAccessor.java setPropertyValues:97, AbstractPropertyAccessor (org.springframework.beans), AbstractPropertyAccessor.java setPropertyValues:77, AbstractPropertyAccessor (org.springframework.beans), AbstractPropertyAccessor.java applyPropertyValues:1732, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support), AbstractAutowireCapableBeanFactory.java populateBean:1444, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support), AbstractAutowireCapableBeanFactory.java doCreateBean:594, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support), AbstractAutowireCapableBeanFactory.java createBean:517, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support), AbstractAutowireCapableBeanFactory.java lambda$doGetBean$0:323, AbstractBeanFactory (org.springframework.beans.factory.support), AbstractBeanFactory.java getObject:-1, 1713129148 (org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$195), Unknown Source getSingleton:226, DefaultSingletonBeanRegistry (org.springframework.beans.factory.support), DefaultSingletonBeanRegistry.java doGetBean:321, AbstractBeanFactory (org.springframework.beans.factory.support), AbstractBeanFactory.java getBean:202, AbstractBeanFactory (org.springframework.beans.factory.support), AbstractBeanFactory.java getBeansOfType:621, DefaultListableBeanFactory (org.springframework.beans.factory.support), DefaultListableBeanFactory.java getBeansOfType:1251, AbstractApplicationContext (org.springframework.context.support), AbstractApplicationContext.java beansOfTypeIncludingAncestors:378, BeanFactoryUtils (org.springframework.beans.factory), BeanFactoryUtils.java afterPropertiesSet:140, ReferenceBean (com.alibaba.dubbo.config.spring), ReferenceBean.java invokeInitMethods:1855, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support), AbstractAutowireCapableBeanFactory.java initializeBean:1792, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support), AbstractAutowireCapableBeanFactory.java doCreateBean:595, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support), AbstractAutowireCapableBeanFactory.java createBean:517, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support), AbstractAutowireCapableBeanFactory.java lambda$doGetBean$0:323, AbstractBeanFactory (org.springframework.beans.factory.support), AbstractBeanFactory.java getObject:-1, 1713129148 (org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$195), Unknown Source getSingleton:226, DefaultSingletonBeanRegistry (org.springframework.beans.factory.support), DefaultSingletonBeanRegistry.java doGetBean:321, AbstractBeanFactory (org.springframework.beans.factory.support), AbstractBeanFactory.java getTypeForFactoryBean:1646, AbstractBeanFactory (org.springframework.beans.factory.support), AbstractBeanFactory.java getTypeForFactoryBean:895, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support), AbstractAutowireCapableBeanFactory.java isTypeMatch:613, AbstractBeanFactory (org.springframework.beans.factory.support), AbstractBeanFactory.java doGetBeanNamesForType:537, DefaultListableBeanFactory (org.springframework.beans.factory.support), DefaultListableBeanFactory.java getBeanNamesForType:495, DefaultListableBeanFactory (org.springframework.beans.factory.support), DefaultListableBeanFactory.java getBeansOfType:617, DefaultListableBeanFactory (org.springframework.beans.factory.support), DefaultListableBeanFactory.java getBeansOfType:609, DefaultListableBeanFactory (org.springframework.beans.factory.support), DefaultListableBeanFactory.java getBeansOfType:1243, AbstractApplicationContext (org.springframework.context.support), AbstractApplicationContext.java processPropertyPlaceHolders:367, MapperScannerConfigurer (org.mybatis.spring.mapper), MapperScannerConfigurer.java postProcessBeanDefinitionRegistry:338, MapperScannerConfigurer (org.mybatis.spring.mapper), MapperScannerConfigurer.java invokeBeanDefinitionRegistryPostProcessors:280, PostProcessorRegistrationDelegate (org.springframework.context.support), PostProcessorRegistrationDelegate.java invokeBeanFactoryPostProcessors:126, PostProcessorRegistrationDelegate (org.springframework.context.support), PostProcessorRegistrationDelegate.java invokeBeanFactoryPostProcessors:707, AbstractApplicationContext (org.springframework.context.support), AbstractApplicationContext.java refresh:533, AbstractApplicationContext (org.springframework.context.support), AbstractApplicationContext.java refresh:143, ServletWebServerApplicationContext (org.springframework.boot.web.servlet.context), ServletWebServerApplicationContext.java refresh:758, SpringApplication (org.springframework.boot), SpringApplication.java refresh:750, SpringApplication (org.springframework.boot), SpringApplication.java refreshContext:397, SpringApplication (org.springframework.boot), SpringApplication.java run:315, SpringApplication (org.springframework.boot), SpringApplication.java main:36, DcRemoteApplication (com.yc.dc.remote), DcRemoteApplication.java

从调用栈,发现一点奇怪的调用路径:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzgxyf.html