【问题标题】:Errors when running SpringBoot Admin app运行 Spring Boot Admin 应用程序时出错
【发布时间】:2017-02-24 04:20:33
【问题描述】:

我正在尝试使用 Springboot 管理应用程序,但无法使基础工作正常。

我从最简单的 springboot web 应用程序开始(使用 starter-web 和 starter-test)并添加了 springboot-admin-serverspringboot-admin-server-ui 到依赖项列表。

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>


    <!-- Added Dependency for Admin Server and its UI --> 
    <dependency>
        <groupId>de.codecentric</groupId>
        <artifactId>spring-boot-admin-server</artifactId>
        <version>1.4.5</version> 
    </dependency>
    <dependency>
        <groupId>de.codecentric</groupId>
        <artifactId>spring-boot-admin-server-ui</artifactId>
        <version>1.4.5</version> 
    </dependency>


</dependencies>

尝试执行 mvn clean package 会引发错误。根本原因如下所示。

Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.embedded.ServletRegistrationBean
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_112]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_112]
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) ~[na:1.8.0_112]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_112]
    ... 51 common frames omitted

springboot 应用绝对是准系统实现(如下图添加了 EnableAdminServer 注解)

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import de.codecentric.boot.admin.config.EnableAdminServer;

    @SpringBootApplication
    @EnableAdminServer
    public class WorkingExampleSpringBootAdminApplication {

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

我猜出现这个错误是因为这个类(org.springframework.boot.context.embedded.ServletRegistrationBean)已经被替换为org.springframework.boot.web.servlet.ServletRegistrationBean(在1.5.x),这很可能被 spring-boot-admin-server 组件使用。

我通过切换到 Springboot 的早期版本(比如 1.4.4)解决了这个问题。这是正确的做法吗?还是我的配置有错误?

【问题讨论】:

    标签: spring maven spring-boot spring-boot-admin


    【解决方案1】:

    使用 spring-boot-admin-server 和 spring-boot-admin-server-ui 的 1.4.6 版本而不是 1.4.5 可以解决此问题。

    【讨论】:

      猜你喜欢
      • 2017-02-18
      • 2015-04-18
      • 2020-06-04
      • 2021-04-19
      • 1970-01-01
      • 2017-10-08
      相关资源
      最近更新 更多