Spring Boot Admin 使用的坑

这几天公司需要部署SpringBootAdmin监控,用来时刻关注微服务的状态

按照官网的操作非常简单:

1. 添加依赖到pom.xml

    <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-server</artifactId>
            <version>${springboot.admin.version}</version>
        </dependency>

        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-server-ui</artifactId>
            <version>${springboot.admin.version}</version>
        </dependency> 

2. 启动类Application添加注解@EnableAdminServer

3. 如果本身是用SpringCloud管理,比如我们用的是Eureka管理服务的,所以添加@EnableEurekaClient,让AdminServer作为一个微服务被集中治理,而每个其它的微服务都可以被访问到监控状态。

4. 但这样不会监控微服务的服务本身,所以需要在有注解@EnableEurekaServer的服务上,做Admin客户端的配置

        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-client</artifactId>
            <version>${springboot.admin.version}</version>
        </dependency>

然后在yml中添加配置spring.boot.admin.url: http://localhost:8760即可

步骤很简单,但部署后却发现访问页面只有footer的几个链接(我们用的版本是1.4.0,与使用的SpringBoot版本一致)

从访问来看,core.css出现404错误,于是反编译jar包,发现1.4.0对应的spring-boot-admin-server-ui没有core.css,反复尝试后,换用1.4.1版本的,解决!

也就是说,作为非Spring官方出品的Spring Boot Admin还是有瑕疵的,但这只是历史版本的问题

另外,还有一个地方,就是每个微服务需要把/heath放入访问白名单中(PermitAll)才行。

猜你喜欢

转载自www.cnblogs.com/roostinghawk/p/12274689.html