运行Springboot出现Cannot instantiate interface org.springframework.context.ApplicationListener错误

springboot运行项目中代码并无问题,但是运行application(主入口)报错:
Cannot instantiate interface org.springframework.context.ApplicationListener : org.springframework.boot.cloud.CloudFoundryVcapEnvironmentPostProcessor
报错代码:

java.lang.IllegalArgumentException: Cannot instantiate interface org.springframework.context.ApplicationListener : org.springframework.boot.cloud.CloudFoundryVcapEnvironmentPostProcessor
	at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:441)
	at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:420)
	at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:411)
	at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:268)
	at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:247)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1234)
	at com.bingqi.App.main(App.java:19)
Caused by: java.lang.IllegalArgumentException: class org.springframework.boot.cloud.CloudFoundryVcapEnvironmentPostProcessor is not assignable to interface org.springframework.context.ApplicationListener
	at org.springframework.util.Assert.assignableCheckFailed(Assert.java:655)
	at org.springframework.util.Assert.isAssignable(Assert.java:586)
	at org.springframework.util.Assert.isAssignable(Assert.java:617)
	at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:434)
	... 7 more

通过排错发现,pom中引入的两个外来jar包中也引用的springboot,这个与自己pom引用的springboot的相关包发生冲突,导致无法初始化!
简而言之就是springboot出现版本不一致,出现冲突。

解决方法

1.这两个外来jar包改groupId和artifactId,这个命名方式随意自己喜欢,我就是将下面的***com***改成了***zom***,因此编译时将这个包中的引用放到了后面,因为a-z。

<dependency>
    <groupId>zom.bbd.onet</groupId>
    <artifactId>onet-parent</artifactId>
    <version>1.0-SANPSHOT</version>
</dependency>

<dependency>
    <groupId>zom.bbd.onet</groupId>
    <artifactId>onet.class</artifactId>
    <version>1.0-SANPSHOT</version>
</dependency>

更改方式如下:
右侧maven -> Execute maven goal -> 输入命令:
mvn install:install-file -Dfile=/xx/xx/libs/Onet/sdk.jar -DgroupId=zom.bbd.onet -DartifactId=onet-parent -Dversion=1.0-SANPSHOT -Dpackaging=jar
成功之后在pom中重新加入你写的依赖即可!

2.将冲突的springboot版本一致,我这里将pom中引入的spring-boot-starter-parent从2.2.6改成了2.0.0。再运行没有出错。

总结:两个方法可能都需要做,一般只做方式2问题既可以解决!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值