Spring Cloud入门教程-微服务监控Spring Boot Admin

org.jolokia

jolokia-core

org.springframework.cloud

spring-cloud-starter-security

org.springframework.boot

spring-boot-starter-test

test

org.springframework.boot

spring-boot-maven-plugin

改版本的 spring cloud 没有相应的 spring-boot-admin-starter-server 版本,这里使用2.0.1 版本,需加上版本号。

启动类加上注解@EnableAdminServer和@EnableEurekaClient

@EnableEurekaClient

@EnableAdminServer

@SpringBootApplication

@ComponentScan(“com.springcloud.demo.adminserver”)

public class AdminServerApplication {

public static void main(String[] args) {

SpringApplication.run(AdminServerApplication.class, args);

}

}

配置文件配置端口号、程序名、服务注册中心地址和安全配置:

server.port=5000

spring.application.name=admin-server

spring.security.user.name=admin

spring.security.user.password=admin

eureka.instance.metadata-map.user.name=${spring.security.user.name}

eureka.instance.metadata-map.user.password=${spring.security.user.password}

eureka.client.service-url.defaultZone=http://localhost:8791/eureka/

eureka.instance.health-check-url-path=/actuator/health

management.endpoints.web.exposure.include=*

management.endpoint.health.show-details=always

新增一个安全配置类。

@Configuration

public class SecuritySecureConfig extends WebSecurityConfigurerAdapter {

private final String adminContextPath;

public SecuritySecureConfig(AdminServerProperties adminServerProperties) {

this.adminContextPath = adminServerProperties.getContextPath();

}

@Override

protected void configure(HttpSecurity http) throws Exception {

// @formatter:off

SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();

successHandler.setTargetUrlParameter(“redirectTo”);

http.authorizeRequests()

.antMatchers(adminContextPath + “/assets/**”).permitAll()

.antMatchers(adminContextPath + “/login”).permitAll()

.anyRequest().authenticated()

.and()

.formLogin().loginPage(adminContextPath + “/login”).successHandler(successHandler).and()

.logout().logoutUrl(adminContextPath + “/logout”).and()

.httpBasic().and()

.csrf().disable();

}

}

创建客户端

=====

新建module admin-client :

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd”>

4.0.0

com.springcloud.demo

springcloud-demo

1.0-SNAPSHOT

admin-client

0.0.1-SNAPSHOT

jar

admin-client

Demo project for Spring Boot

org.springframework.boot

spring-boot-starter-web

org.springframework.boot

spring-boot-starter-actuator

de.codecentric

spring-boot-admin-starter-client

2.0.1

org.springframework.cloud

spring-cloud-starter-netflix-eureka-client

org.springframework.boot

spring-boot-starter-test

test

总结

在清楚了各个大厂的面试重点之后,就能很好的提高你刷题以及面试准备的效率,接下来小编也为大家准备了最新的互联网大厂资料。

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

ope>test

总结

在清楚了各个大厂的面试重点之后,就能很好的提高你刷题以及面试准备的效率,接下来小编也为大家准备了最新的互联网大厂资料。

[外链图片转存中…(img-BFsYUnWV-1714455488703)]

[外链图片转存中…(img-cr66HYdt-1714455488704)]

[外链图片转存中…(img-UnzVCLwq-1714455488704)]

[外链图片转存中…(img-GY7pHUID-1714455488705)]

本文已被CODING开源项目:【一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码】收录

  • 12
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要将nacos和spring-boot-admin集成,需要进行以下步骤: 1. 在pom.xml中添加以下依赖: ```xml <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-server</artifactId> <version>2.2.3</version> </dependency> ``` 2. 在application.properties中添加以下配置: ```properties spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848 # nacos服务地址 spring.application.name=spring-boot-admin-server # 应用名 server.port=8080 # 服务端口 spring.boot.admin.server.url=http://localhost:${server.port} # spring-boot-admin服务地址 spring.boot.admin.client.url=http://localhost:${server.port} # spring-boot-admin客户端地址 management.endpoints.web.exposure.include=* # 开启所有端点 ``` 3. 在启动类上添加@EnableDiscoveryClient和@EnableAdminServer注解: ```java @SpringBootApplication @EnableDiscoveryClient @EnableAdminServer public class SpringBootAdminApplication { public static void main(String[] args) { SpringApplication.run(SpringBootAdminApplication.class, args); } } ``` 4. 在需要监控的应用中添加spring-boot-starter-actuator依赖,并在application.properties中添加以下配置: ```properties spring.boot.admin.client.url=http://localhost:8080 # spring-boot-admin服务地址 spring.boot.admin.client.username=admin # 认证用户名 spring.boot.admin.client.password=admin # 认证密码 ``` 5. 启动nacos和spring-boot-admin服务,然后启动需要监控的应用,即可在spring-boot-admin控制台中查看应用的监控信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值