Spring Boot、Zipkin和Eureka服务器不起作用。

huangapple go评论56阅读模式
英文:

springboot zipkin and eureka server not working

问题

我正在尝试构建一个Spring Boot微服务应用程序,其中有一个名为Eureka Server的服务,它需要Zipkin来追踪日志。然而,当我添加最新版本的依赖项时,出现以下错误。

java.lang.IllegalArgumentException: Could not find class [org.springframework.cloud.client.loadbalancer.LoadBalancerEagerLoadProperties]
	at org.springframework.util.ClassUtils.resolveClassName(ClassUtils.java:333) ~[spring-core-6.0.3.jar:6.0.3]
	at org.springframework.core.annotation.TypeMappedAnnotation.adapt(TypeMappedAnnotation.java:465) ~[spring-core-6.0.3.jar:6.0.3]
	at org.springframework.core.annotation.TypeMappedAnnotation.getValue(TypeMappedAnnotation.java:390) ~[spring-core-6.0.3.jar:6.0.3]
	at org.springframework.core.annotation.TypeMappedAnnotation.asMap(TypeMappedAnnotation.java:278) ~[spring-core-6.0.3.jar:6.0.3]
	at org.springframework.core.annotation.AbstractMergedAnnotation.asAnnotationAttributes(AbstractMergedAnnotation.java:193) ~[spring-core-6.0.3.jar:6.0.3]
	at org.springframework.core.type.AnnotatedTypeMetadata.getAnnotationAttributes(AnnotatedTypeMetadata.java:106) ~[spring-core-6.0.3.jar:6.0.3]
	at org.springframework.core.type.AnnotatedTypeMetadata.getAnnotationAttributes(AnnotatedTypeMetadata.java:81) ~[spring-core-6.0.3.jar:6.0.3]
	at org.springframework.context.annotation.AnnotationConfigUtils.attributesFor(AnnotationConfigUtils.java:301) ~[spring-context-6.0.3.jar:6.0.3]

我的POM文件:

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
    <spring.boot.dependencies.version>3.0.1</spring.boot.dependencies.version>
    <spring.cloud-version>2020.0.3</spring.cloud-version>
</properties>

<dependencies>
    <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-netflix-eureka-server -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        <version>4.0.0</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-sleuth</artifactId>
        <version>3.1.6</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-sleuth-zipkin</artifactId>
        <version>3.1.6</version>
    </dependency>
</dependencies>

应用属性文件:

spring.application.name=eureka-server
server.port=8761
eureka.client.fetch-registry=false
eureka.client.register-with-eureka=false
log.level.root=debug
spring.zipkin.base-url=http://localhost:9411

我搜索了错误并发现可能是一个Spring Cloud类的版本差异问题导致的,然而,当我使用较早版本的Eureka依赖项时,无法显示Eureka主页,浏览http://localhost:8761/也不起作用。依赖管理也无效。

英文:

I am trying to build a springboot microservice application and i have service called eureka server which require zipkin to trace the logs.However when i add the dependencies with the latest,it gives the following error.

java.lang.IllegalArgumentException: Could not find class [org.springframework.cloud.client.loadbalancer.LoadBalancerEagerLoadProperties]
at org.springframework.util.ClassUtils.resolveClassName(ClassUtils.java:333) ~[spring-core-6.0.3.jar:6.0.3]
at org.springframework.core.annotation.TypeMappedAnnotation.adapt(TypeMappedAnnotation.java:465) ~[spring-core-6.0.3.jar:6.0.3]
at org.springframework.core.annotation.TypeMappedAnnotation.getValue(TypeMappedAnnotation.java:390) ~[spring-core-6.0.3.jar:6.0.3]
at org.springframework.core.annotation.TypeMappedAnnotation.asMap(TypeMappedAnnotation.java:278) ~[spring-core-6.0.3.jar:6.0.3]
at org.springframework.core.annotation.AbstractMergedAnnotation.asAnnotationAttributes(AbstractMergedAnnotation.java:193) ~[spring-core-6.0.3.jar:6.0.3]
at org.springframework.core.type.AnnotatedTypeMetadata.getAnnotationAttributes(AnnotatedTypeMetadata.java:106) ~[spring-core-6.0.3.jar:6.0.3]
at org.springframework.core.type.AnnotatedTypeMetadata.getAnnotationAttributes(AnnotatedTypeMetadata.java:81) ~[spring-core-6.0.3.jar:6.0.3]
at org.springframework.context.annotation.AnnotationConfigUtils.attributesFor(AnnotationConfigUtils.java:301) ~[spring-context-6.0.3.jar:6.0.3]

My pom:

 &lt;properties&gt;
&lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
&lt;maven.compiler.source&gt;1.7&lt;/maven.compiler.source&gt;
&lt;maven.compiler.target&gt;1.7&lt;/maven.compiler.target&gt;
&lt;spring.boot.dependencies.version&gt;3.0.1&lt;/spring.boot.dependencies.version&gt;
&lt;spring.cloud-version&gt;2020.0.3&lt;/spring.cloud-version&gt;
&lt;/properties&gt;
&lt;dependencies&gt;
&lt;!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-netflix-eureka-server --&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
&lt;artifactId&gt;spring-cloud-starter-netflix-eureka-server&lt;/artifactId&gt;
&lt;version&gt;4.0.0&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
&lt;artifactId&gt;spring-cloud-starter-sleuth&lt;/artifactId&gt;
&lt;version&gt;3.1.6&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
&lt;artifactId&gt;spring-cloud-sleuth-zipkin&lt;/artifactId&gt;
&lt;version&gt;3.1.6&lt;/version&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;

Properties.application:

spring.application.name=eureka-server
server.port=8761
eureka.client.fetch-registry=false
eureka.client.register-with-eureka=false
log.level.root=debug
spring.zipkin.base-url=http://localhost:9411

I search for the error and find there may be the problem on the version difference in one spring.cloud class and cause the error, however, when i use earlier version eureka dependencies, it cannot show the eureka homepage when browsing http://localhost:8761/.Neither the use of dependency
management works

答案1

得分: 0

我在你的pom中看到了1.7版本,这个版本已经不再受支持了。
[![jdk7支持日期][1]][1]
查看更多详细信息,如果你打开https://start.spring.io/并添加eureka服务器,它会生成以下的pom文件,其中使用的是java 17版本。

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
<!-- 省略其他部分 -->
&lt;properties&gt;
    &lt;java.version&gt;17&lt;/java.version&gt;
    &lt;spring-cloud.version&gt;2022.0.1&lt;/spring-cloud.version&gt;
&lt;/properties&gt;
<!-- 省略其他部分 -->

如果你需要低于17版本,可以使用spring boot 2.7,它会生成以下pom文件。

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
<!-- 省略其他部分 -->
&lt;properties&gt;
    &lt;java.version&gt;1.8&lt;/java.version&gt;
    &lt;spring-cloud.version&gt;2021.0.5&lt;/spring-cloud.version&gt;
&lt;/properties&gt;
<!-- 省略其他部分 -->

创建项目时,请使用https://start.spring.io/。 [1]: https://i.stack.imgur.com/yBlne.png

英文:

I see source 1.7 in your pom which is not supported anymore
[![jdk7 support dates][1]][1]
check for more details, If you open https://start.spring.io/ and add eureka server it generates pom below which uses java 17

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
  xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  &lt;parent&gt;
    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
    &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
    &lt;version&gt;3.0.3&lt;/version&gt;
    &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
  &lt;/parent&gt;
  &lt;groupId&gt;com.example&lt;/groupId&gt;
  &lt;artifactId&gt;demo&lt;/artifactId&gt;
  &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  &lt;name&gt;demo&lt;/name&gt;
  &lt;description&gt;Demo project for Spring Boot&lt;/description&gt;
  &lt;properties&gt;
    &lt;java.version&gt;17&lt;/java.version&gt;
    &lt;spring-cloud.version&gt;2022.0.1&lt;/spring-cloud.version&gt;
  &lt;/properties&gt;
  &lt;dependencies&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
      &lt;artifactId&gt;spring-cloud-starter-netflix-eureka-server&lt;/artifactId&gt;
    &lt;/dependency&gt;

    &lt;dependency&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
      &lt;scope&gt;test&lt;/scope&gt;
    &lt;/dependency&gt;
  &lt;/dependencies&gt;
  &lt;dependencyManagement&gt;
    &lt;dependencies&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
        &lt;artifactId&gt;spring-cloud-dependencies&lt;/artifactId&gt;
        &lt;version&gt;${spring-cloud.version}&lt;/version&gt;
        &lt;type&gt;pom&lt;/type&gt;
        &lt;scope&gt;import&lt;/scope&gt;
      &lt;/dependency&gt;
    &lt;/dependencies&gt;
  &lt;/dependencyManagement&gt;

  &lt;build&gt;
    &lt;plugins&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
      &lt;/plugin&gt;
    &lt;/plugins&gt;
  &lt;/build&gt;
  &lt;repositories&gt;
    &lt;repository&gt;
      &lt;id&gt;netflix-candidates&lt;/id&gt;
      &lt;name&gt;Netflix Candidates&lt;/name&gt;
      &lt;url&gt;https://artifactory-oss.prod.netflix.net/artifactory/maven-oss-candidates&lt;/url&gt;
      &lt;snapshots&gt;
        &lt;enabled&gt;false&lt;/enabled&gt;
      &lt;/snapshots&gt;
    &lt;/repository&gt;
  &lt;/repositories&gt;

&lt;/project&gt;

if you need to go below 17 you can use spring boot 2.7 which generates pom below

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
  xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  &lt;parent&gt;
    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
    &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
    &lt;version&gt;2.7.9&lt;/version&gt;
    &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
  &lt;/parent&gt;
  &lt;groupId&gt;com.example&lt;/groupId&gt;
  &lt;artifactId&gt;demo&lt;/artifactId&gt;
  &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  &lt;name&gt;demo&lt;/name&gt;
  &lt;description&gt;Demo project for Spring Boot&lt;/description&gt;
  &lt;properties&gt;
    &lt;java.version&gt;1.8&lt;/java.version&gt;
    &lt;spring-cloud.version&gt;2021.0.5&lt;/spring-cloud.version&gt;
  &lt;/properties&gt;
  &lt;dependencies&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
      &lt;artifactId&gt;spring-cloud-starter-netflix-eureka-server&lt;/artifactId&gt;
    &lt;/dependency&gt;

    &lt;dependency&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
      &lt;scope&gt;test&lt;/scope&gt;
    &lt;/dependency&gt;
  &lt;/dependencies&gt;
  &lt;dependencyManagement&gt;
    &lt;dependencies&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
        &lt;artifactId&gt;spring-cloud-dependencies&lt;/artifactId&gt;
        &lt;version&gt;${spring-cloud.version}&lt;/version&gt;
        &lt;type&gt;pom&lt;/type&gt;
        &lt;scope&gt;import&lt;/scope&gt;
      &lt;/dependency&gt;
    &lt;/dependencies&gt;
  &lt;/dependencyManagement&gt;

  &lt;build&gt;
    &lt;plugins&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
      &lt;/plugin&gt;
    &lt;/plugins&gt;
  &lt;/build&gt;

&lt;/project&gt;

please use https://start.spring.io/ when creating a project.
[1]: https://i.stack.imgur.com/yBlne.png

huangapple
  • 本文由 发表于 2023年2月24日 01:43:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/75548448.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定