alibaba / dubbo-spring-boot-starter

Dubbo Spring Boot Starter
Apache License 2.0
2.1k stars 745 forks source link

DubboProperties中为什么存在applications等这些参数? #88

Open littlefisher666 opened 6 years ago

littlefisher666 commented 6 years ago

生产方的服务上加上了com.alibaba.dubbo.config.annotation.Service注解

@Service(interfaceClass = ISystemParamService.class, application = "user-deploy")
public class SystemParamServiceImpl extends ServiceImpl implements ISystemParamService {
    // interface
}

Application方法上加了com.alibaba.dubbo.config.spring.context.annotation.DubboComponentScan用于扫描上面的Service

@SpringBootApplication
@EnableDubboConfiguration
@MapperScan("com.littlefisher.**.dal.mapper")
@ComponentScan(basePackages = {"com.littlefisher.**"})
@DubboComponentScan(basePackages = "com.littlefisher.**.service.impl")
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}

这么配置的话,会有如下报错

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
22:25:21.468 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.alibaba.dubbo.spring.boot.DubboProviderAutoConfiguration': Invocation of init method failed; nested exception is java.lang.NullPointerException: beanName=systemParamServiceImpl, application=user-deploy not found in multi configs
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:138) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:423) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1702) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:583) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:760) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:388) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1234) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
    at com.littlefisher.user.deploy.Application.main(Application.java:29) [classes/:?]
Caused by: java.lang.NullPointerException: beanName=systemParamServiceImpl, application=user-deploy not found in multi configs
    at com.alibaba.dubbo.spring.boot.DubboCommonAutoConfiguration.parseApplication(DubboCommonAutoConfiguration.java:141) ~[dubbo-spring-boot-starter-2.0.0.jar:?]
    at com.alibaba.dubbo.spring.boot.DubboProviderAutoConfiguration.initProviderBean(DubboProviderAutoConfiguration.java:63) ~[dubbo-spring-boot-starter-2.0.0.jar:?]
    at com.alibaba.dubbo.spring.boot.DubboProviderAutoConfiguration.init(DubboProviderAutoConfiguration.java:45) ~[dubbo-spring-boot-starter-2.0.0.jar:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_151]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_151]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_151]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_151]
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:369) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:312) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:135) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    ... 18 more

追踪了一下源码,在DubboCommonAutoConfiguration类的initIdConfigMap方法里,会初始化一堆xxxs的参数放在ID_CONFIG_MAP中,这些参数就是DubboProperties中。可在平时配置时,是不会配置applications这样的参数的。

另外看说明,服务上加com.alibaba.dubbo.config.annotation.Service注解之外,还要加Component注解,可看源码发现,其实加了com.alibaba.dubbo.config.annotation.Service注解,Dubbo是会把这个类加到spring bean中的。

所以不太理解是什么原因,还请释疑。

谢谢

villins commented 6 years ago

也是报这个错误

peijie-sh commented 6 years ago

我也有这个疑问,等待解答