Spring Boot Admin Server 2.1.6 的使用

使用报错

  • Spring Boot 2.2.0 及以上版本 整合 Spring Boot Admin Server 2.1.6 及以下版本,会出现如下错误:java.lang.NoClassDefFoundError: org/springframework/web/servlet/config/annotation/WebMvcConfigurer,
    报错的原因是 SpringBoot2.2.0、2.2.1 没有 spring webMvc:jar 包。

  • 如果添加 spring-boot-start-web 包 或 spring-webmvc 包,就会出现 创建bean 的错误。org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webHandler' defined in class path resource

  • 基于以上问题,推测 Spring Boot 2.2.0 及以上版本 不能整合 Spring Boot Admin Server 2.1.6 及以下版本

正常使用推荐

  • Spring Boot 2.1.6 及以下版本 整合 Spring Boot Admin Server 2.1.6 及以下版本可以正常使用,
  • 如果单独整合 Spring Boot Admin Server 只需要导入 spring-boot-admin-server-ui 包 即可
  • 以下是完整的 pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.6.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.harmony</groupId>
    <artifactId>demo-name</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo-name</name>
    <description>XXXXX</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-server-ui</artifactId>
            <version>2.1.6</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

启动类加上注解@EnableAdminServer即可运行

@EnableAdminServer
@SpringBootApplication
public class DemoNameApplication {

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

}

客户端在application.yml 中做如下配置即可

spring:
  boot:
    admin:
      client:
      	##监控地址服务地址
        url: "spring-boot-admin-server-url"
management:
  endpoints:
    web:
      exposure:
        include: "*"

因为版本问题,耽搁了好长时间,以此为戒,以后遇到框架里的类不存在时,找不到其他问题时,注意jar包版本问题

发布了12 篇原创文章 · 获赞 0 · 访问量 472

猜你喜欢

转载自blog.csdn.net/w0iloveyou/article/details/103270712