springboot+dubbo ApplicationConfig.application == null

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.IllegalStateException: ApplicationConfig.application == null
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:139) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:414) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1770) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:849) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
	at com.mintoujf.springboot.SpringbootDubboProviderApplication.main(SpringbootDubboProviderApplication.java:12) [classes/:na]
Caused by: java.lang.IllegalStateException: ApplicationConfig.application == null
	at com.alibaba.dubbo.config.AbstractConfig.appendParameters(AbstractConfig.java:245) ~[dubbo-2.6.0.jar:2.6.0]
	at com.alibaba.dubbo.config.AbstractConfig.appendParameters(AbstractConfig.java:180) ~[dubbo-2.6.0.jar:2.6.0]
	at com.alibaba.dubbo.config.AbstractInterfaceConfig.loadRegistries(AbstractInterfaceConfig.java:175) ~[dubbo-2.6.0.jar:2.6.0]
	at com.alibaba.dubbo.config.ServiceConfig.doExportUrls(ServiceConfig.java:355) ~[dubbo-2.6.0.jar:2.6.0]
	at com.alibaba.dubbo.config.ServiceConfig.doExport(ServiceConfig.java:316) ~[dubbo-2.6.0.jar:2.6.0]
	at com.alibaba.dubbo.config.ServiceConfig.export(ServiceConfig.java:215) ~[dubbo-2.6.0.jar:2.6.0]
	at com.alibaba.dubbo.spring.boot.DubboProviderAutoConfiguration.initProviderBean(DubboProviderAutoConfiguration.java:84) ~[dubbo-spring-boot-starter-2.0.0.jar:na]
	at com.alibaba.dubbo.spring.boot.DubboProviderAutoConfiguration.init(DubboProviderAutoConfiguration.java:45) ~[dubbo-spring-boot-starter-2.0.0.jar:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_151]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_151]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_151]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_151]
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:363) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:307) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:136) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	... 18 common frames omitted
Caused by: java.lang.IllegalStateException: ApplicationConfig.application == null
	at com.alibaba.dubbo.config.AbstractConfig.appendParameters(AbstractConfig.java:230) ~[dubbo-2.6.0.jar:2.6.0]
	... 32 common frames omitted

学习springboot+dubbo集合的时候,遇到了个问题ApplicationConfig.application == null。
最后找到原因是由于版本冲突导致的。
之前我的pom依赖的dubbo-spring-boot-starter版本是2.0.0

<dependency>
            <groupId>com.alibaba.spring.boot</groupId>
            <artifactId>dubbo-spring-boot-starter</artifactId>
            <version>2.0.0</version>
 </dependency>

把版本号改成

 <version>1.0.2</version>

就行了

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
在使用SpringBoot + Dubbo框架的项目中集成Seata,需要进行以下步骤: 1. 添加Seata的相关依赖 在项目的pom.xml文件中添加Seata的相关依赖: ```xml <dependency> <groupId>io.seata</groupId> <artifactId>seata-all</artifactId> <version>${seata.version}</version> </dependency> ``` 2. 配置Seata的注册中心 在项目的application.properties或application.yml文件中添加Seata的注册中心配置,例如: ```yaml spring: cloud: alibaba: seata: tx-service-group: my_test_tx_group config: type: nacos nacos: server-addr: localhost:8848 namespace: seata registry: type: nacos nacos: server-addr: localhost:8848 application: seata-server ``` 其中,tx-service-group是Seata的事务组名称,config和registry是Seata的注册中心配置,这里使用的是Nacos作为注册中心,也可以使用其他的注册中心。 3. 配置Dubbo的Seata拦截器 在Dubbo的服务提供方和服务消费方中都需要添加Seata的拦截器,以实现分布式事务的管理。在SpringBoot + Dubbo框架中,可以通过配置文件或注解的方式来添加Seata的拦截器。 (1)配置文件方式 在Dubbo的服务提供方和服务消费方的application.properties或application.yml文件中添加Seata的拦截器配置,例如: ```yaml # 服务提供方 dubbo.provider.filter=seata # 服务消费方 dubbo.consumer.filter=seata ``` (2)注解方式 在Dubbo的服务提供方和服务消费方的实现类中,使用@DubboService和@DubboReference注解来定义Dubbo服务,同时在@DubboService和@DubboReference注解中添加filter属性来指定Seata的拦截器,例如: ```java // 服务提供方 @DubboService(version = "1.0.0", filter = {"seata"}) public class OrderServiceImpl implements OrderService { // ... } // 服务消费方 public class UserServiceImpl implements UserService { @DubboReference(version = "1.0.0", filter = {"seata"}) private OrderService orderService; // ... } ``` 4. 编写分布式事务代码 在Dubbo的服务提供方和服务消费方中,通过Seata提供的API来实现分布式事务的管理,例如: ```java // 服务提供方 @Service public class OrderServiceImpl implements OrderService { @Override @GlobalTransactional public void createOrder(Order order) { // 保存订单信息 orderMapper.insert(order); // 扣减库存 storageService.reduceStock(order.getProductId(), order.getCount()); // 扣减余额 accountService.reduceBalance(order.getUserId(), order.getMoney()); } } // 服务消费方 @Service public class UserServiceImpl implements UserService { @DubboReference(version = "1.0.0") private OrderService orderService; @Override @GlobalTransactional public void createUser(User user, Order order) { // 注册用户 userMapper.insert(user); // 创建订单 orderService.createOrder(order); } } ``` 在以上代码中,使用@GlobalTransactional注解来标记分布式事务的范围,Seata会根据这个注解来创建全局事务,并在所有涉及到的服务中进行事务的协调和管理。 综上所述,以上就是在SpringBoot + Dubbo框架中使用Seata进行分布式事务管理的步骤。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值