DawnSouther opened a new issue #9470:
URL: https://github.com/apache/dubbo/issues/9470


   <!-- If you need to report a security issue please visit 
https://github.com/apache/dubbo/security/policy -->
   
   - [ x ] I have searched the [issues](https://github.com/apache/dubbo/issues) 
of this repository and believe that this is not a duplicate.
   
   ## Ask your question here
   
   ### 环境版本
   [email protected]
   [email protected]
   [email protected]
   [email protected]
   
   ### 报错信息
   ```
   2021-12-22 19:18:33.433 DEBUG 23496 --- [           main] 
o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of 
singleton bean 'dubboApplication'
   2021-12-22 19:18:33.434 DEBUG 23496 --- [           main] 
o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of 
singleton bean 'com.example.CloudAutoConfiguration'
   2021-12-22 19:18:33.435 DEBUG 23496 --- [           main] 
o.s.b.f.s.DefaultListableBeanFactory     : Bean creation exception on eager 
FactoryBean type check: 
org.springframework.beans.factory.BeanCreationException: Error creating bean 
with name 'fileRemoteService': Invocation of init method failed; nested 
exception is org.springframework.beans.factory.BeanCreationException: Error 
creating bean with name 'com.example.CloudAutoConfiguration': Instantiation of 
bean failed; nested exception is 
org.springframework.beans.BeanInstantiationException: Failed to instantiate 
[com.example.CloudAutoConfiguration]: No default constructor found; nested 
exception is java.lang.NoSuchMethodException: 
com.example.CloudAutoConfiguration.<init>()
   2021-12-22 19:18:33.436 DEBUG 23496 --- [           main] 
o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of 
singleton bean 'dubboApplication'
   2021-12-22 19:18:33.436 DEBUG 23496 --- [           main] 
o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of 
singleton bean 'com.example.CloudAutoConfiguration'
   2021-12-22 19:18:33.437 DEBUG 23496 --- [           main] 
o.s.b.f.s.DefaultListableBeanFactory     : Bean creation exception on eager 
FactoryBean type check: 
org.springframework.beans.factory.BeanCreationException: Error creating bean 
with name 'budgetReleaseService': Invocation of init method failed; nested 
exception is org.springframework.beans.factory.BeanCreationException: Error 
creating bean with name 'com.example.CloudAutoConfiguration': Instantiation of 
bean failed; nested exception is 
org.springframework.beans.BeanInstantiationException: Failed to instantiate 
[com.example.CloudAutoConfiguration]: No default constructor found; nested 
exception is java.lang.NoSuchMethodException: 
com.example.CloudAutoConfiguration.<init>()
   ```
   
   ### dubbo配置
   ```xml
   <?xml version="1.0" encoding="UTF-8"?>
   <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
          xmlns:dubbo="http://dubbo.apache.org/schema/dubbo";
          xmlns="http://www.springframework.org/schema/beans";
          xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
          http://dubbo.apache.org/schema/dubbo 
http://dubbo.apache.org/schema/dubbo/dubbo.xsd";>
   
       <dubbo:reference interface="com.example.IProcurementApplyService"
                        id="procurementApplyService"
                        timeout="60000"
                        group="good"
                        check="false"
                        version="160.0.0-ns"/>
   
   </beans>
   ```
   
   ```java
   @Configuration(proxyBeanMethods = false)
   public class CloudAutoConfiguration {
   
       @Bean
       public static DubboPropertyStaticConstantConfigurer 
dubboPropertyStaticConstantConfigurer(){
           return new DubboPropertyStaticConstantConfigurer();
       }
   
       public CloudAutoConfiguration(NacosDiscoveryProperties 
nacosDiscoveryProperties,
                                     @Value(APPLICATION_CODE) String 
serviceCode) {
           nacosDiscoveryProperties.getMetadata().put(KEY_SERVICE_CODE, 
serviceCode);
       }
   
       @Bean
       public ApplicationConfig dubboApplication(@Value(APPLICATION_NAME) 
String applicationName){
           ApplicationConfig applicationConfig = new ApplicationConfig();
           applicationConfig.setName(applicationName);
           return applicationConfig;
       }
   
       @Bean
       public RegistryConfig dubboRegistry(NacosDiscoveryProperties 
nacosDiscoveryProperties){
           Map<String, String> map = new HashMap<>();
           map.put("namespace", nacosDiscoveryProperties.getNamespace());
           RegistryConfig registryConfig = new RegistryConfig();
           registryConfig.setProtocol(REGISTER_CENTER);
           registryConfig.setAddress(nacosDiscoveryProperties.getServerAddr());
           registryConfig.setParameters(map);
           return registryConfig;
       }
   
       @Bean
       public ConfigCenterConfig dubboConfigCenter(NacosConfigProperties 
nacosConfigProperties){
           ConfigCenterConfig configCenterConfig = new ConfigCenterConfig();
           configCenterConfig.setProtocol(REGISTER_CENTER);
           configCenterConfig.setAddress(nacosConfigProperties.getServerAddr());
           
configCenterConfig.setNamespace(nacosConfigProperties.getNamespace());
           return configCenterConfig;
       }
   
       @Bean
       public ProtocolConfig dubboProtocol(){
           ProtocolConfig protocolConfig = new ProtocolConfig();
           protocolConfig.setId("dubbo-protocol");
           protocolConfig.setName(PROTOCOL);
           protocolConfig.setPort(-1);
           return protocolConfig;
       }
   
       @Bean
       public ConsumerConfig dubboConsumer(){
           ConsumerConfig consumerConfig = new ConsumerConfig();
           consumerConfig.setTimeout(TIMEOUT);
           consumerConfig.setFilter(CONSUMER_FILTER);
           return consumerConfig;
       }
   
       @Bean
       public ProviderConfig dubboProvider(){
           ProviderConfig providerConfig = new ProviderConfig();
           providerConfig.setTimeout(TIMEOUT);
           providerConfig.setFilter(PROVIDER_FILTER);
           return providerConfig;
       }
   
   }
   
   ```
   
   ### 问题描述
   
在[email protected]版本以后,引入了@DependsOnDatabaseInitialization注解,该注解会调用beanFactory.findAnnotationOnBean(beanName,
 DependsOnDatabaseInitialization.class)方法,造成ReferenceBean的提前初始化
   
![image](https://user-images.githubusercontent.com/22205542/147086720-e17ea715-3be1-4c5d-9d6a-393b34cfbb60.png)
   并且,在引入spring-cloud-starter-sleuth这种组件也会造成bean的提前初始化
   
![image](https://user-images.githubusercontent.com/22205542/147086860-bddfc3ba-1e20-452a-a512-c0d01b76c7fa.png)
   
   
   ### 尝试解决
   
我移除掉了spring-cloud-starter-sleuth组件,但是没有办法移除@DependsOnDatabaseInitialization的执行。
   
   
有没有其他办法解决这种提前初始化的error。我已经遇上了很多次,每次只能通过改用不触发提前初始化的组件来解决,但是spring-boot我真的移除不了,我难道要永远不升级2.5.x吗?
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to