spring cloud的坑

Posted flyaway2013

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了spring cloud的坑相关的知识,希望对你有一定的参考价值。

接入nacos 之后,想把所有的配置丢上去。

启动程序是:

@EnableDiscoveryClient
@RestController
@ComponentScan(basePackages = {"com.lkk"})
@MapperScan(basePackages = {"com.lkk.ppm.doc.service.dao"})
@ImportResource(locations = {"classpath:dubbo.xml"})
@EnableTransactionManagement
@Import({Settings.class, WebConfig.class})
@SpringBootApplication(exclude = {SecurityAutoConfiguration.class})
@EnableWebMvc
@Slf4j
public class DocApplication {

bootstrap.yml文件是:

spring:
  application:
    name: llk_discuss_app
  profiles:
    active: ${PROFILE_ACTIVE:local}
  cloud:
    nacos:
      discovery:
        server-addr: ${NACOS_SERVER_ADDR:192.168.11.196:8848}
        namespace: ${NACOS_CONFIG_NAMESPACE:1f3c60b6-3e28-44eb-9798-7f7eeeff6a8d}
        #group: ${NACOS_CONFIG_GROUP:llk}
      config:
        server-addr: ${NACOS_SERVER_ADDR:192.168.11.196:8848}
        file-extension: yaml
        namespace: ${NACOS_CONFIG_NAMESPACE:1f3c60b6-3e28-44eb-9798-7f7eeeff6a8d}
        group: ${NACOS_CONFIG_GROUP:llk}
        ext-config[0]:
          data-id: llk_stateflow_toggle.yaml
          group: ${NACOS_CONFIG_GROUP:llk}
          refresh: true
          

 

dubbo.xml 文件是:

   <dubbo:registry  address="${NACOS_ADDR:nacos://127.0.0.1:8848}"  file="erdp_discuss_app.cache"/>
   <dubbo:service interface="com.llk.ppm.discuss.domain.service.ELDiscussService" ref="discussService"/>
   <dubbo:reference id="peopleService" interface="com.llk.platform.system.domain.service.ELPeopleService"/>

...

 

错误是

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘peopleService: FactoryBean threw exception on object creation; nested exception is java.lang.NumberFormatException: For input string: "8848}"
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:178) ~[spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:101) ~[spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1644) ~[spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getObjectForBeanInstance(AbstractAutowireCapableBeanFactory.java:1174) ~[spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:257) ~[spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251) ~[spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.addCandidateEntry(DefaultListableBeanFactory.java:1322) ~[spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1288) ~[spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1098) ~[spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1062) ~[spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:581) ~[spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    ... 30 common frames omitted
Caused by: java.lang.NumberFormatException: For input string: "8848}"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[na:1.8.0_201]
    at java.lang.Integer.parseInt(Integer.java:580) ~[na:1.8.0_201]
    at java.lang.Integer.parseInt(Integer.java:615) ~[na:1.8.0_201]
    at com.alibaba.dubbo.common.URL.valueOf(URL.java:239) ~[dubbo-2.6.5.jar:2.6.5]
    at com.alibaba.dubbo.common.utils.UrlUtils.parseURL(UrlUtils.java:68) ~[dubbo-2.6.5.jar:2.6.5]
    at com.alibaba.dubbo.common.utils.UrlUtils.parseURLs(UrlUtils.java:137) ~[dubbo-2.6.5.jar:2.6.5]
    at com.alibaba.dubbo.config.AbstractInterfaceConfig.loadRegistries(AbstractInterfaceConfig.java:191) ~[dubbo-2.6.5.jar:2.6.5]
    at com.alibaba.dubbo.config.ReferenceConfig.createProxy(ReferenceConfig.java:378) ~[dubbo-2.6.5.jar:2.6.5]
    at com.alibaba.dubbo.config.ReferenceConfig.init(ReferenceConfig.java:333) ~[dubbo-2.6.5.jar:2.6.5]
    at com.alibaba.dubbo.config.ReferenceConfig.get(ReferenceConfig.java:163) ~[dubbo-2.6.5.jar:2.6.5]
    at com.alibaba.dubbo.config.spring.ReferenceBean.getObject(ReferenceBean.java:67) ~[dubbo-2.6.5.jar:2.6.5]
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:171) ~[spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    ... 41 common frames omitted

花了整整一天时间,各种折腾,dubbo.xml 里面的占位符就是解析不了。


开始是以为是nacos的bug,后面以为是dubbo 的问题,最后才发现是spring-cloud-commons 的问题。我晕~~~~


开始是以为是bootstrap的问题,初始化dubbo.xml的时间太早了吗? 坑爹啊! 研究了下boostrap 和 application 配置文件的关系。无果。  后面认为是yml的格式的问题,后面把bootstrap.yml, 转换成了boostrap.properties, 结果问题依旧。想来想去,应该是xml解析的时候,bootstrap 还没有从nacos 成功获取数据的原因吧! 写了个demo试了下,好像可以了, 再套到了原来的项目里面来, 熄火了!。 可是,这到底是什么情况,bootstrap配置文件的优先级是比较高的啊! 网上一把搜索,未果,好像大家都没有遇到我这个问题。。。 后面干脆不用bootstrap配置文件,使用 application.yml/properties吧,可以了,但是nacos怎么办,不能不使用bootstrap啊!!

是ImportSource问题吗,它的解析有特殊之处, 研究其原理,无果?后面同事偶然发现,只要把dubbo.xml 分开为两个文件(一个文件有是基本信息,另外一个文件是 service/reference)就可以正常启动了, 然后继续研究,发现把 dubbo:reference 的id 属性去掉,就可以了。。 把原来的一个dubbo xml 分开了两个xml,两次ImportSource,另外还糅合导入了一个properties 就可以了,是顺序问题吗? 难道是第一次不能解析,第二次才能解析吗?。。。必须要分开吗?折腾N久,无果。从GitHub拉下来几个demo(大名鼎鼎的didi哥的学习项目),运行一把,没问题的啊!!对比一下,然后一点点的加减代码和配置吧! 发现didi哥的项目简单,所以无错,我把代码套过去,它的项目也会一样的报错了。

调试一下吧! 断点设置在RegistryConfig的setAddress方法之上。看到其堆栈, 正常的是:
setAddress:118, RegistryConfig (com.alibaba.dubbo.config)
invoke0:-1, NativeMethodAccessorImpl (sun.reflect)
invoke:62, NativeMethodAccessorImpl (sun.reflect)
invoke:43, DelegatingMethodAccessorImpl (sun.reflect)
invoke:498, Method (java.lang.reflect)
setValue:332, BeanWrapperImpl$BeanPropertyHandler (org.springframework.beans)
processLocalProperty:458, AbstractNestablePropertyAccessor (org.springframework.beans)
setPropertyValue:278, AbstractNestablePropertyAccessor (org.springframework.beans)
setPropertyValue:266, AbstractNestablePropertyAccessor (org.springframework.beans)
setPropertyValues:97, AbstractPropertyAccessor (org.springframework.beans)
setPropertyValues:77, AbstractPropertyAccessor (org.springframework.beans)
applyPropertyValues:1635, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
populateBean:1354, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
doCreateBean:572, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
createBean:495, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
lambda$doGetBean$0:317, AbstractBeanFactory (org.springframework.beans.factory.support)
getObject:-1, 1089930529 (org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$136)
getSingleton:222, DefaultSingletonBeanRegistry (org.springframework.beans.factory.support)
doGetBean:315, AbstractBeanFactory (org.springframework.beans.factory.support)
getBean:199, AbstractBeanFactory (org.springframework.beans.factory.support)
preInstantiateSingletons:759, DefaultListableBeanFactory (org.springframework.beans.factory.support)
finishBeanFactoryInitialization:869, AbstractApplicationContext (org.springframework.context.support)
refresh:550, AbstractApplicationContext (org.springframework.context.support)
refresh:140, ServletWebServerApplicationContext (org.springframework.boot.web.servlet.context)
refresh:780, SpringApplication (org.springframework.boot)
refreshContext:412, SpringApplication (org.springframework.boot)
run:333, SpringApplication (org.springframework.boot)
run:1277, SpringApplication (org.springframework.boot)
run:1265, SpringApplication (org.springframework.boot)
main:24, TestApplication (com.didispace.alibaba.nacos.config.client)

异常情况的堆栈是:
setAddress:118, RegistryConfig (com.alibaba.dubbo.config)
invoke0:-1, NativeMethodAccessorImpl (sun.reflect)
invoke:62, NativeMethodAccessorImpl (sun.reflect)
invoke:43, DelegatingMethodAccessorImpl (sun.reflect)
invoke:498, Method (java.lang.reflect)
setValue:332, BeanWrapperImpl$BeanPropertyHandler (org.springframework.beans)
processLocalProperty:458, AbstractNestablePropertyAccessor (org.springframework.beans)
setPropertyValue:278, AbstractNestablePropertyAccessor (org.springframework.beans)
setPropertyValue:266, AbstractNestablePropertyAccessor (org.springframework.beans)
setPropertyValues:97, AbstractPropertyAccessor (org.springframework.beans)
setPropertyValues:77, AbstractPropertyAccessor (org.springframework.beans)
applyPropertyValues:1630, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
populateBean:1349, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
doCreateBean:572, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
createBean:495, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
lambda$doGetBean$0:317, AbstractBeanFactory (org.springframework.beans.factory.support)
getObject:-1, 1376017854 (org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$135)
getSingleton:222, DefaultSingletonBeanRegistry (org.springframework.beans.factory.support)
doGetBean:315, AbstractBeanFactory (org.springframework.beans.factory.support)
getBean:199, AbstractBeanFactory (org.springframework.beans.factory.support)
getBeansOfType:514, DefaultListableBeanFactory (org.springframework.beans.factory.support)
getBeansOfType:1204, AbstractApplicationContext (org.springframework.context.support)
beansOfTypeIncludingAncestors:327, BeanFactoryUtils (org.springframework.beans.factory)
afterPropertiesSet:140, ReferenceBean (com.alibaba.dubbo.config.spring)
invokeInitMethods:1753, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
initializeBean:1690, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
doCreateBean:573, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
createBean:495, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
lambda$doGetBean$0:317, AbstractBeanFactory (org.springframework.beans.factory.support)
getObject:-1, 1376017854 (org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$135)
getSingleton:222, DefaultSingletonBeanRegistry (org.springframework.beans.factory.support)
doGetBean:315, AbstractBeanFactory (org.springframework.beans.factory.support)
getTypeForFactoryBean:1513, AbstractBeanFactory (org.springframework.beans.factory.support)
getTypeForFactoryBean:838, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
isTypeMatch:562, AbstractBeanFactory (org.springframework.beans.factory.support)
doGetBeanNamesForType:426, DefaultListableBeanFactory (org.springframework.beans.factory.support)
getBeanNamesForType:389, DefaultListableBeanFactory (org.springframework.beans.factory.support)
getBeanNamesForType:383, DefaultListableBeanFactory (org.springframework.beans.factory.support)
resolveNamedBean:996, DefaultListableBeanFactory (org.springframework.beans.factory.support)
getBean:338, DefaultListableBeanFactory (org.springframework.beans.factory.support)
getBean:333, DefaultListableBeanFactory (org.springframework.beans.factory.support)
isApplicable:163, RefreshAutoConfiguration$RefreshScopeBeanDefinitionEnhancer (org.springframework.cloud.autoconfigure)
postProcessBeanDefinitionRegistry:134, RefreshAutoConfiguration$RefreshScopeBeanDefinitionEnhancer (org.springframework.cloud.autoconfigure)
invokeBeanDefinitionRegistryPostProcessors:271, PostProcessorRegistrationDelegate (org.springframework.context.support)
invokeBeanFactoryPostProcessors:121, PostProcessorRegistrationDelegate (org.springframework.context.support)
invokeBeanFactoryPostProcessors:692, AbstractApplicationContext (org.springframework.context.support)
refresh:530, AbstractApplicationContext (org.springframework.context.support)
refresh:140, ServletWebServerApplicationContext (org.springframework.boot.web.servlet.context)
refresh:754, SpringApplication (org.springframework.boot)
refreshContext:386, SpringApplication (org.springframework.boot)
run:307, SpringApplication (org.springframework.boot)
main:48, TestNacosApplication (com.example.test_nacos)

一帧一帧的查看分析:

0 = "org.springframework.context.annotation.internalConfigurationAnnotationProcessor"
1 = "org.springframework.cloud.autoconfigure.RefreshAutoConfiguration$RefreshScopeBeanDefinitionEnhancer"
2 = "refreshScope"

难道是internalConfigurationAnnotationProcessor的问题? 不像。发现RefreshAutoConfiguration 有些不对, 好像是RefreshAutoConfiguration 引起了这个问题?但是此时我依然不知道这就是RefreshAutoConfiguration的bug!(后面才知道) RefreshAutoConfiguration 为什么要这么做?不管了先, 那就把RefreshAutoConfiguration 停掉啊! 观察到配置项:spring.cloud.refresh.enabled,这个好像没什么用。那把它设置为false,然后重启,然后就可以了! 我擦,终于解决了问题!!不过,似乎高兴得太早了,引起的问题是, nacos的配置完全读取不到了!! 这怎么行呢!

同事的配置拿来研究,调试发现它的堆栈更深了:

技术图片
setAddress:118, RegistryConfig (com.alibaba.dubbo.config)
invoke0:-1, NativeMethodAccessorImpl (sun.reflect)
invoke:62, NativeMethodAccessorImpl (sun.reflect)
invoke:43, DelegatingMethodAccessorImpl (sun.reflect)
invoke:498, Method (java.lang.reflect)
setValue:332, BeanWrapperImpl$BeanPropertyHandler (org.springframework.beans)
processLocalProperty:458, AbstractNestablePropertyAccessor (org.springframework.beans)
setPropertyValue:278, AbstractNestablePropertyAccessor (org.springframework.beans)
setPropertyValue:266, AbstractNestablePropertyAccessor (org.springframework.beans)
setPropertyValues:97, AbstractPropertyAccessor (org.springframework.beans)
setPropertyValues:77, AbstractPropertyAccessor (org.springframework.beans)
applyPropertyValues:1630, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
populateBean:1349, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
doCreateBean:572, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
createBean:495, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
lambda$doGetBean$0:317, AbstractBeanFactory (org.springframework.beans.factory.support)
getObject:-1, 26928827 (org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$135)
getSingleton:222, DefaultSingletonBeanRegistry (org.springframework.beans.factory.support)
doGetBean:315, AbstractBeanFactory (org.springframework.beans.factory.support)
getBean:199, AbstractBeanFactory (org.springframework.beans.factory.support)
getBeansOfType:514, DefaultListableBeanFactory (org.springframework.beans.factory.support)
getBeansOfType:1204, AbstractApplicationContext (org.springframework.context.support)
beansOfTypeIncludingAncestors:327, BeanFactoryUtils (org.springframework.beans.factory)
afterPropertiesSet:140, ReferenceBean (com.alibaba.dubbo.config.spring)
invokeInitMethods:1753, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
initializeBean:1690, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
doCreateBean:573, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
createBean:495, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
lambda$doGetBean$0:317, AbstractBeanFactory (org.springframework.beans.factory.support)
getObject:-1, 26928827 (org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$135)
getSingleton:222, DefaultSingletonBeanRegistry (org.springframework.beans.factory.support)
doGetBean:315, AbstractBeanFactory (org.springframework.beans.factory.support)
getTypeForFactoryBean:1513, AbstractBeanFactory (org.springframework.beans.factory.support)
getTypeForFactoryBean:838, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
isTypeMatch:562, AbstractBeanFactory (org.springframework.beans.factory.support)
doGetBeanNamesForType:426, DefaultListableBeanFactory (org.springframework.beans.factory.support)
getBeanNamesForType:389, DefaultListableBeanFactory (org.springframework.beans.factory.support)
beanNamesForTypeIncludingAncestors:214, BeanFactoryUtils (org.springframework.beans.factory)
findAutowireCandidates:1273, DefaultListableBeanFactory (org.springframework.beans.factory.support)
doResolveDependency:1098, DefaultListableBeanFactory (org.springframework.beans.factory.support)
resolveDependency:1062, DefaultListableBeanFactory (org.springframework.beans.factory.support)
resolveAutowiredArgument:819, ConstructorResolver (org.springframework.beans.factory.support)
createArgumentArray:725, ConstructorResolver (org.springframework.beans.factory.support)
instantiateUsingFactoryMethod:475, ConstructorResolver (org.springframework.beans.factory.support)
instantiateUsingFactoryMethod:1246, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
createBeanInstance:1096, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
doCreateBean:535, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
createBean:495, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
lambda$doGetBean$0:317, AbstractBeanFactory (org.springframework.beans.factory.support)
getObject:-1, 26928827 (org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$135)
getSingleton:222, DefaultSingletonBeanRegistry (org.springframework.beans.factory.support)
doGetBean:315, AbstractBeanFactory (org.springframework.beans.factory.support)
getBean:204, AbstractBeanFactory (org.springframework.beans.factory.support)
registerBeanPostProcessors:224, PostProcessorRegistrationDelegate (org.springframework.context.support)
registerBeanPostProcessors:708, AbstractApplicationContext (org.springframework.context.support)
refresh:533, AbstractApplicationContext (org.springframework.context.support)
refresh:140, ServletWebServerApplicationContext (org.springframework.boot.web.servlet.context)
refresh:754, SpringApplication (org.springframework.boot)
refreshContext:386, SpringApplication (org.springframework.boot)
run:307, SpringApplication (org.springframework.boot)
main:64, DiscussApplication (com.llk.ppm.discuss)
View Code



可见异常情况下,堆栈深了不少,但是依然不知道具体原因。然后继续加减研究,发现把 dubbo:reference 的id 属性去掉,就可以了!!! 观察发现去掉之后就beanDefinition names不会包含这个reference, 之前是367, 现在变成了367:

技术图片
org.s[email protected]44c5a16f: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,testNacosApplication,org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory,helloService222,helloService,helloService1,repositoryController,profileController,alpsController,repositorySchemaController,repositoryEntityController,repositoryPropertyReferenceController,repositorySearchController,aaaaaaa,com.alibaba.dubbo.config.RegistryConfig,com.alibaba.dubbo.config.ProviderConfig,dubbo,com.lkk.ppm.discuss.domain.service.ELDiscussService,bbbbbbbb,org.springframework.boot.autoconfigure.AutoConfigurationPackages,org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration,org.springframework.boot.autoconfigure.condition.BeanTypeRegistry,propertySourcesPlaceholderConfigurer,org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration$TomcatWebSocketConfiguration,websocketServletWebServerCustomizer,org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration,org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryConfiguration$EmbeddedTomcat,tomcatServletWebServerFactory,org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration,servletWebServerFactoryCustomizer,tomcatServletWebServerFactoryCustomizer,server-org.springframework.boot.autoconfigure.web.ServerProperties,org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor,org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata,webServerFactoryCustomizerBeanPostProcessor,errorPageRegistrarBeanPostProcessor,org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration$DispatcherServletConfiguration,dispatcherServlet,spring.mvc-org.springframework.boot.autoconfigure.web.servlet.WebMvcProperties,org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration$DispatcherServletRegistrationConfiguration,dispatcherServletRegistration,org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration,org.springframework.cloud.netflix.archaius.ArchaiusAutoConfiguration$PropagateEventsConfiguration,org.springframework.cloud.netflix.archaius.ArchaiusAutoConfiguration,configurableEnvironmentConfiguration,org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration,defaultValidator,methodValidationPostProcessor,org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration,error,beanNameViewResolver,org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$DefaultErrorViewResolverConfiguration,conventionErrorViewResolver,org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration,errorAttributes,basicErrorController,errorPageCustomizer,preserveErrorControllerTargetClassPostProcessor,spring.resources-org.springframework.boot.autoconfigure.web.ResourceProperties,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter$FaviconConfiguration,faviconHandlerMapping,faviconRequestHandler,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration,requestMappingHandlerAdapter,requestMappingHandlerMapping,mvcConversionService,mvcValidator,mvcContentNegotiationManager,mvcPathMatcher,mvcUrlPathHelper,viewControllerHandlerMapping,beanNameHandlerMapping,resourceHandlerMapping,mvcResourceUrlProvider,defaultServletHandlerMapping,mvcUriComponentsContributor,httpRequestHandlerAdapter,simpleControllerHandlerAdapter,handlerExceptionResolver,mvcViewResolver,mvcHandlerMappingIntrospector,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter,defaultViewResolver,viewResolver,welcomePageHandlerMapping,requestContextFilter,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration,hiddenHttpMethodFilter,httpPutFormContentFilter,org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari,dataSource,org.springframework.boot.autoconfigure.jdbc.DataSourceJmxConfiguration$Hikari,org.springframework.boot.autoconfigure.jdbc.DataSourceJmxConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$PooledDataSourceConfiguration,org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration$HikariPoolDataSourceMetadataProviderConfiguration,hikariPoolDataSourceMetadataProvider,org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker,org.springframework.boot.autoconfigure.jdbc.DataSourceInitializationConfiguration,dataSourceInitializerPostProcessor,org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,spring.datasource-org.springframework.boot.autoconfigure.jdbc.DataSourceProperties,com.baomidou.mybatisplus.spring.boot.starter.MybatisPlusAutoConfiguration$MapperScannerRegistrarNotFoundConfiguration,com.baomidou.mybatisplus.spring.boot.starter.MybatisPlusAutoConfiguration,sqlSessionFactory,sqlSessionTemplate,mybatis-plus-com.baomidou.mybatisplus.spring.boot.starter.MybatisPlusProperties,org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration$MapperScannerRegistrarNotFoundConfiguration,org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration,mybatis-org.mybatis.spring.boot.autoconfigure.MybatisProperties,org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration,mbeanExporter,objectNamingStrategy,mbeanServer,org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration,springApplicationAdminRegistrar,org.springframework.boot.autoconfigure.aop.AopAutoConfiguration$CglibAutoProxyConfiguration,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.boot.autoconfigure.aop.AopAutoConfiguration,org.springframework.cloud.autoconfigure.RefreshAutoConfiguration$RefreshScopeBeanDefinitionEnhancer,org.springframework.cloud.autoconfigure.RefreshAutoConfiguration,refreshScope,loggingRebinder,contextRefresher,refreshEventListener,org.springframework.boot.autoconfigure.data.redis.LettuceConnectionConfiguration,lettuceClientResources,redisConnectionFactory,org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration,redisTemplate,stringRedisTemplate,spring.redis-org.springframework.boot.autoconfigure.data.redis.RedisProperties,org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfiguration,org.springframework.boot.autoconfigure.dao.PersistenceExceptionTranslationAutoConfiguration,persistenceExceptionTranslationPostProcessor,org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration,mongo,spring.data.mongodb-org.springframework.boot.autoconfigure.mongo.MongoProperties,org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration,mongoDbFactory,mongoTemplate,mappingMongoConverter,mongoMappingContext,gridFsTemplate,mongoCustomConversions,org.springframework.boot.autoconfigure.data.mongo.MongoRepositoriesAutoConfiguration,org.springframework.boot.autoconfigure.data.redis.RedisReactiveAutoConfiguration,reactiveRedisTemplate,org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration,keyValueMappingContext,redisCustomConversions,redisReferenceResolver,redisConverter,redisKeyValueAdapter,redisKeyValueTemplate,org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration,gsonBuilder,gson,standardGsonBuilderCustomizer,spring.gson-org.springframework.boot.autoconfigure.gson.GsonProperties,org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$Jackson2ObjectMapperBuilderCustomizerConfiguration,standardJacksonObjectMapperBuilderCustomizer,spring.jackson-org.springframework.boot.autoconfigure.jackson.JacksonProperties,org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperBuilderConfiguration,jacksonObjectMapperBuilder,org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$ParameterNamesModuleConfiguration,parameterNamesModule,org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperConfiguration,jacksonObjectMapper,org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration,jsonComponentModule,org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration$StringHttpMessageConverterConfiguration,stringHttpMessageConverter,spring.http.encoding-org.springframework.boot.autoconfigure.http.HttpEncodingProperties,org.springframework.boot.autoconfigure.http.JacksonHttpMessageConvertersConfiguration$MappingJackson2HttpMessageConverterConfiguration,mappingJackson2HttpMessageConverter,org.springframework.boot.autoconfigure.http.JacksonHttpMessageConvertersConfiguration,org.springframework.boot.autoconfigure.http.GsonHttpMessageConvertersConfiguration,org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration,messageConverters,org.springframework.hateoas.config.EntityLinksConfiguration,entityLinksPluginRegistry,delegatingEntityLinks,controllerEntityLinks,controllerLinkBuilderFactoryBean,org.springframework.hateoas.config.JaxRsConfigurationImportSelector$JaxRsEntityLinksConfiguration,jaxRsEntityLinks,org.springframework.hateoas.config.HateoasConfiguration,linkRelationMessageSource,jackson2ModuleRegisteringBeanPostProcessor,defaultRelProvider,annotationRelProvider,_relProvider,relProviderPluginRegistry,linkDiscoverers,linkDiscovererRegistry,org.springframework.data.web.config.SpringDataJacksonConfiguration,jacksonGeoModule,org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration,repositories,repositoryRelProvider,persistentEntities,defaultConversionService,validatingRepositoryEventListener,jpaHelper,repositoryRestConfiguration,projectionDefinitionRegistrar,metadataConfiguration,baseUri,annotatedEventHandlerInvoker,domainObjectMerger,serverHttpRequestMethodArgumentResolver,repoRequestArgumentResolver,resourceMetadataHandlerMethodArgumentResolver,backendIdHandlerMethodArgumentResolver,eTagArgumentResolver,entityLinks,persistentEntityArgumentResolver,jsonSchemaConverter,resourceDescriptionMessageSourceAccessor,jacksonHttpMessageConverter,halJacksonHttpMessageConverter,uriListHttpMessageConverter,resourceProcessorInvoker,repositoryExporterHandlerAdapter,restHandlerMapping,resourceMappings,linkCollector,excerptProjector,repositoryRestExceptionHandler,repositoryInvokerFactory,defaultMessageConverters,alpsJsonHttpMessageConverter,pageableResolver,sortResolver,backendIdConverterRegistry,auditableBeanWrapperFactory,httpHeadersPreparer,selfLinkProvider,associationLinks,enumTranslator,alpsConverter,profileResourceProcessor,pagedResourcesAssembler,pagedResourcesAssemblerArgumentResolver,org.springframework.hateoas.config.ConverterRegisteringWebMvcConfigurer#0,org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration,springBootRepositoryRestConfigurer,spring.data.rest-org.springframework.boot.autoconfigure.data.rest.RepositoryRestProperties,org.springframework.boot.autoconfigure.hateoas.HypermediaHttpMessageConverterConfiguration,halMessageConverterSupportedMediaTypeCustomizer,org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration,spring.hateoas-org.springframework.boot.autoconfigure.hateoas.HateoasProperties,org.springframework.boot.autoconfigure.http.codec.CodecsAutoConfiguration$JacksonCodecConfiguration,jacksonCodecCustomizer,org.springframework.boot.autoconfigure.http.codec.CodecsAutoConfiguration,org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration,spring.info-org.springframework.boot.autoconfigure.info.ProjectInfoProperties,org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration$JdbcTemplateConfiguration,jdbcTemplate,org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration$NamedParameterJdbcTemplateConfiguration,namedParameterJdbcTemplate,org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration,spring.jdbc-org.springframework.boot.autoconfigure.jdbc.JdbcProperties,org.springframework.boot.autoconfigure.reactor.core.ReactorCoreAutoConfiguration,spring.reactor-org.springframework.boot.autoconfigure.reactor.core.ReactorCoreProperties,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration$DataSourceTransactionManagerConfiguration,transactionManager,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration,org.springframework.transaction.config.internalTransactionAdvisor,transactionAttributeSource,transactionInterceptor,org.springframework.transaction.config.internalTransactionalEventListenerFactory,org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration$EnableTransactionManagementConfiguration$CglibAutoProxyConfiguration,org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration$EnableTransactionManagementConfiguration,org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration$TransactionTemplateConfiguration,transactionTemplate,org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration,platformTransactionManagerCustomizers,spring.transaction-org.springframework.boot.autoconfigure.transaction.TransactionProperties,org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration,restTemplateBuilder,org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration$TomcatWebServerFactoryCustomizerConfiguration,tomcatWebServerFactoryCustomizer,org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration,org.springframework.boot.autoconfigure.web.servlet.HttpEncodingAutoConfiguration,characterEncodingFilter,localeCharsetMappingsCustomizer,org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration,multipartConfigElement,multipartResolver,spring.servlet.multipart-org.springframework.boot.autoconfigure.web.servlet.MultipartProperties,org.springframework.cloud.alibaba.nacos.NacosConfigAutoConfiguration,nacosConfigProperties,nacosRefreshProperties,nacosRefreshHistory,nacosContextRefresher,org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationConfiguration,spring.cloud.service-registry.auto-registration-org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationProperties,org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationAutoConfiguration,org.springframework.cloud.alibaba.nacos.NacosDiscoveryAutoConfiguration,nacosServiceRegistry,nacosRegistration,nacosAutoServiceRegistration,org.springframework.cloud.alibaba.nacos.discovery.NacosDiscoveryClientAutoConfiguration,nacosProperties,nacosDiscoveryClient,nacosWatch,org.springframework.cloud.netflix.ribbon.RibbonAutoConfiguration,ribbonFeature,springClientFactory,loadBalancerClient,propertiesFactory,default.org.springframework.cloud.netflix.ribbon.RibbonAutoConfiguration.RibbonClientSpecification,ribbon.eager-load-org.springframework.cloud.netflix.ribbon.RibbonEagerLoadProperties,ribbon-org.springframework.cloud.netflix.ribbon.ServerIntrospectorProperties,org.springframework.cloud.alibaba.nacos.ribbon.RibbonNacosAutoConfiguration,default.org.springframework.cloud.alibaba.nacos.ribbon.RibbonNacosAutoConfiguration.RibbonClientSpecification,org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration,configurationPropertiesBeans,configurationPropertiesRebinder,org.springframework.cloud.autoconfigure.LifecycleMvcEndpointAutoConfiguration,environmentManager,org.springframework.cloud.client.CommonsClientAutoConfiguration,org.springframework.cloud.client.discovery.composite.CompositeDiscoveryClientAutoConfiguration,compositeDiscoveryClient,org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClientAutoConfiguration,simpleDiscoveryProperties,simpleDiscoveryClient,org.springframework.cloud.client.loadbalancer.AsyncLoadBalancerAutoConfiguration$LoadBalancerInterceptorConfig,asyncLoadBalancerInterceptor,asyncRestTemplateCustomizer,org.springframework.cloud.client.loadbalancer.AsyncLoadBalancerAutoConfiguration$AsyncRestTemplateCustomizerConfig,loadBalancedAsyncRestTemplateInitializer,org.springframework.cloud.client.loadbalancer.AsyncLoadBalancerAutoConfiguration,org.springframework.cloud.client.loadbalancer.LoadBalancerAutoConfiguration$LoadBalancerInterceptorConfig,ribbonInterceptor,restTemplateCustomizer,org.springframework.cloud.client.loadbalancer.LoadBalancerAutoConfiguration,loadBalancedRestTemplateInitializerDeprecated,loadBalancerRequestFactory,spring.cloud.loadbalancer.retry-org.springframework.cloud.client.loadbalancer.LoadBalancerRetryProperties,org.springframework.cloud.client.serviceregistry.ServiceRegistryAutoConfiguration,org.springframework.cloud.commons.httpclient.HttpClientConfiguration$ApacheHttpClientConfiguration,connManFactory,apacheHttpClientBuilder,apacheHttpClientFactory,org.springframework.cloud.commons.httpclient.HttpClientConfiguration,org.springframework.cloud.commons.util.UtilAutoConfiguration,inetUtilsProperties,inetUtils]; parent: org.s[email protected]52d239ba
View Code

 

 

然后就不会去解析 registry,然后 registry 里面占位符就不会被提前解析,然后就没问题了! 但是 dubbo:reference 的id 属性可以去掉吗? 领导的回复是否定的。。

但是他的方案确实是可以的,至少启动不报错。后面把他的两个配置文件合并到一个,发现也可以了! 后面仔细对比,一个个的加减配置,发现它的配置的特别之处是:

<dubbo:application name="${spring.application.name}"   logger="slf4j">


我的配置的 dubbo:application name属性没有使用通配符,他的使用了。 确实,只要使用通配符就可以了,但是一个潜在问题是,调试发现application name属性的赋值很多次,前几次是不正确的,后台出现一些列的warning。而且其他配置如果继续使用通配符的话, 又会报错。 我就日了狗了, 感觉dubbo坑爹了。。


那能不能让dubbo reference 延迟加载?把 dubbo 配置的 lazy 设为true,无效。 init设为 false,无效。lazy-init 设为false,报错:


我靠,dubbo竟然不支持默认的bean的配置,坑爹。 难道要我改dubbo 源码?。。。


这样看来,两种方案都是不可行的。 真是郁闷了,一天半时间了啊! 难道是nacos 的坑吗? 要不要换成携程的apollo 试试。。


bing上搜索RefreshAutoConfiguration bug,终于看到了答案:
https://github.com/spring-cloud/spring-cloud-config/issues/1167
https://github.com/spring-cloud/spring-cloud-commons/commit/9b8a70e5574e1c0e7cb071d4248f7a0d567187ad#diff-09d0c681fbe54b8a84f6bfa2f96ed21b

 
原来是 RefreshAutoConfiguration的 bug,RefreshAutoConfiguration的方法,调用getBean方法, 而它是一个非常重的方法,它直接导致了 提前触发整个beanfactory 解析,加载 以及初始化,而这个时候 springboot 还没有启动完,所以还没来得及从nacos 加载数据, 从而导致了 registry 里面的占位符解析不了( 其实是任何占位符都解析不了。), 从而导致了这个严重问题。 观察到RefreshAutoConfiguration是 spring cloud commons 里面的类,然后看到spring cloud commons是通过spring-cloud-dependencies 指定版本的,我的spring-cloud-dependencies的版本是F:

        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Finchley.SR2</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

           
参照GitHub的那个issue,升级一下改成G版本就好了:

            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Greenwich.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>            

  

不过,似乎高兴得太早了,引起的新问题是,

2019-05-08 11:28:16.584 ERROR 14020 --- [           main] o.s.boot.SpringApplication               : Application run failed

java.lang.AbstractMethodError: null
    at org.springframework.core.OrderComparator.findOrder(OrderComparator.java:141) ~[spring-core-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.core.annotation.AnnotationAwareOrderComparator.findOrder(AnnotationAwareOrderComparator.java:65) ~[spring-core-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.core.OrderComparator.getOrder(OrderComparator.java:124) ~[spring-core-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.core.OrderComparator.getOrder(OrderComparator.java:112) ~[spring-core-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.core.OrderComparator.doCompare(OrderComparator.java:81) ~[spring-core-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.core.OrderComparator.compare(OrderComparator.java:68) ~[spring-core-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at java.util.TimSort.countRunAndMakeAscending(TimSort.java:360) ~[na:1.8.0_201]
    at java.util.TimSort.sort(TimSort.java:220) ~[na:1.8.0_201]
    at java.util.Arrays.sort(Arrays.java:1512) ~[na:1.8.0_201]
    at java.util.ArrayList.sort(ArrayList.java:1462) ~[na:1.8.0_201]
    at org.springframework.boot.SpringApplication.asUnmodifiableOrderedSet(SpringApplication.java:1309) ~[spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
    at org.springframework.boot.SpringApplication.getListeners(SpringApplication.java:1218) ~[spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
    at org.springframework.boot.context.event.EventPublishingRunListener.contextLoaded(EventPublishingRunListener.java:85) ~[spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
    at org.springframework.boot.SpringApplicationRunListeners.contextLoaded(SpringApplicationRunListeners.java:66) ~[spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
    at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:382) ~[spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:305) ~[spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
    at com.example.test_nacos.TestNacosApplication.main(TestNacosApplication.java:53) [classes/:na]
    


看来还是有版本问题,后面发现springboot也要升级到2.1.3.RELEASE。完毕!



参考:
https://github.com/alibaba/nacos/issues/1147
https://github.com/spring-cloud/spring-cloud-config/issues/1167
https://github.com/spring-cloud/spring-cloud-commons/commit/9b8a70e5574e1c0e7cb071d4248f7a0d567187ad#diff-09d0c681fbe54b8a84f6bfa2f96ed21b
https://www.oschina.net/question/3672709_2303162


以上是关于spring cloud的坑的主要内容,如果未能解决你的问题,请参考以下文章

spring cloud eureka 遇到的坑

微服务实施Spring Cloud中踩过的坑(转)

Spring Cloud遇到的坑——服务状态为DOWN

Alibaba Sentinel对接Spring Cloud Gateway关于不显示API管理及请求链路的坑附带解决方案

Spring Cloud 升级最新 Finchley 版本,踩了所有的坑!

spring cloud: 升级到spring boot 2.x/Finchley.RELEASE遇到的坑