接入nacos 以後,想把全部的配置丟上去。java
啓動程序是:react
@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文件是:git
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 文件是:github
<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"/>
...
錯誤是web
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 裏面的佔位符就是解析不了。redis
開始是覺得是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的配置徹底讀取不到了!! 這怎麼行呢!
同事的配置拿來研究,調試發現它的堆棧更深了:spring
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)
可見異常狀況下,堆棧深了很多,可是依然不知道具體緣由。而後繼續加減研究,發現把 dubbo:reference 的id 屬性去掉,就能夠了!!! 觀察發現去掉以後就beanDefinition names不會包含這個reference, 以前是367, 如今變成了366:sql
org.springframework.beans.factory.support.DefaultListableBeanFactory@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.springframework.beans.factory.support.DefaultListableBeanFactory@52d239ba
而後就不會去解析 registry,而後 registry 裏面佔位符就不會被提早解析,而後就沒問題了! 可是 dubbo:reference 的id 屬性能夠去掉嗎? 領導的回覆是否認的。。
可是他的方案確實是能夠的,至少啓動不報錯。後面把他的兩個配置文件合併到一個,發現也能夠了! 後面仔細對比,一個個的加減配置,發現它的配置的特別之處是:mongodb
<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,報錯:apache
元素 'dubbo:reference' 中不容許出現屬性 'lazy-init'。
我靠,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/1147https://github.com/spring-cloud/spring-cloud-config/issues/1167https://github.com/spring-cloud/spring-cloud-commons/commit/9b8a70e5574e1c0e7cb071d4248f7a0d567187ad#diff-09d0c681fbe54b8a84f6bfa2f96ed21bhttps://www.oschina.net/question/3672709_2303162