我开始研究将Spring Boot应用程序从1.5.x迁移到2。 这个appliication依赖于hystrix,它与Spring Boot 2不兼容。 当我在我的pom中有以下内容时:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
<version>1.4.4.RELEASE</version>
</dependency>
启动应用程序时出现以下错误:
java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.<init>([Ljava/lang/Object;)V
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:125)
有人经历过同样的经历吗? 还有解决方案吗?
答案 0 :(得分:2)
经过进一步研究后,我通过在pom文件中添加以下内容找到了解决方案:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.RC1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
所有版本的spring-cloud-dependencies
似乎都与Spring Boot 2.x.x不兼容
答案 1 :(得分:1)
我在启动Spring Boot 2时也遇到了这个问题,因为spring-cloud-starter-hystrix是我在项目中使用的依赖项。但是我发现spring-cloud-starter-hystrix已被弃用。我还发现我在那里使用的伪装类已移至spring-cloud-openfeign(https://github.com/spring-cloud/spring-cloud-openfeign)。因此,我所做的就是从我的依赖项中删除spring-cloud-starter-hystrix,并添加了spring-cloud-openfeign。这对我来说非常合适。
基本上我替换了
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-hystrix', version: '1.4.4.RELEASE'
使用
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-openfeign', version: '2.0.0.RELEASE'
,Spring Boot 2准备就绪。希望这会有所帮助。
注意:我使用Gradle,如果需要的话,您可以轻松找到maven pom依赖项的等效项。
答案 2 :(得分:1)
简而言之, 2.2.0.RELEASE ,我在Spring Boot 2中也遇到了类似的问题。我的mvn项目编译良好,但是Spring Boot应用程序停止启动,没有显示任何实际提示。
有效的解决方案是使用工件 spring-cloud-starter-netflix-hystrix 而不是同一组中的 spring-cloud-starter-hystrix 。然后,您可以使用与Spring Boot相同的版本来检索依赖关系。
来自旧的 pom.xml :
<!-- hysterix -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
<version>1.4.7.RELEASE</version>
</dependency>
工作中的新部分 pom.xml :
<!-- hysterix -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>${spring.boot.version}</version>
</dependency>
答案 3 :(得分:1)
对于 SpringBoot 2.0 版本 artifactID 已更改。旧的依赖是
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
<version>${spring-hystrix.version}</version>
</dependency>
在最新版本中使用这个新的更新依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>2.2.8.RELEASE</version>
</dependency>
对于最近发布的 version
,您可以查看 MVNrepository
答案 4 :(得分:0)
在为使用Spring Boot 2.0.x的Spring Boot微服务集成hystrix时,我遇到了类似的问题。 代替
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
<version>${spring-hystrix.version}</version>
</dependency>
我已移至
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>${spring-hystrix.version}</version>
</dependency>
Spring boot 2.0.x应用程序可以通过spring-cloud-starter-netflix-hystrix依赖项正常启动,而不会出现此问题。
答案 5 :(得分:0)
经过一段时间的研究和测试,这是我发现和注意到的
我认为在最新的 Spring Boot 版本 (2.5.x) 中,Hystrix 看起来已被弃用,或者我只是找不到将其添加为依赖项的方法。
所以我将 Spring boot 版本降级到 2.3.x,在那里我设法运行了应用程序
这里是我工作的 pom.xml 的样子:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.12.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>org.hldservices</groupId>
<artifactId>payment-app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>SpringCloudPaymentCircuitBreakerApplication</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
<spring-cloud.version>Hoxton.SR11</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
请记住,我必须在我的项目中添加以下配置:
SpringCloudPaymentCircuitBreakerApplication(主类)
@EnableHystrix
@EnableHystrixDashboard
application.propreties
management.endpoints.web.exposure.include=*
hystrix.dashboard.proxyStreamAllowList=*