当前位置: 首页 > news >正文

springboot整合admin

1. 添加依赖

首先,在你的admin服务端pom.xml文件中添加Spring Boot Admin的依赖:

<dependency><groupId>de.codecentric</groupId><artifactId>spring-boot-admin-starter-server</artifactId><version>2.5.4</version> <!-- 请根据实际情况选择最新版本 -->
</dependency>

2. 配置Spring Boot Admin Server

在你的Spring Boot应用中,启用Spring Boot Admin Server:

import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
@EnableAdminServer
public class AdminServerApplication {public static void main(String[] args) {SpringApplication.run(AdminServerApplication.class, args);}
}

3. 配置Spring Boot Admin Client

 如果你想要将你的应用注册为Spring Boot Admin的客户端,还需要添加以下依赖:

<dependency><groupId>de.codecentric</groupId><artifactId>spring-boot-admin-starter-client</artifactId><version>2.5.4</version> <!-- 请根据实际情况选择最新版本 -->
</dependency>

如果你想要将你的应用注册为Spring Boot Admin的客户端,需要在application.ymlapplication.properties文件中进行配置:

​
spring:boot:admin:client:url: http://localhost:8080  # Spring Boot Admin Server的地址​

4. 启动应用

启动Spring Boot Admin Server和客户端应用后,访问Spring Boot Admin Server的地址(例如:http://localhost:8080),你将看到注册的客户端应用及其监控信息。

5. 安全配置(可选)

如果你想要保护Spring Boot Admin Server的访问,可以添加Spring Security依赖并进行配置:

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

然后在application.yml中配置用户名和密码:

spring:security:user:name: adminpassword: password

最后,创建一个Spring Security配置类来保护Admin Server的端点:

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {@Overrideprotected void configure(HttpSecurity http) throws Exception {http.csrf().disable().authorizeRequests().anyRequest().authenticated().and().httpBasic();}
}

6.页面访问

http://localhost:port/

http://www.lryc.cn/news/519134.html

相关文章:

  • OS--常见的网络模型(包含IO多路复用的原理)
  • LCE(Local Cascade Ensemble)预测模型和LSTM(Long Short-Term Memory)模型在效果和特点上存在显著差异
  • 【mysql】约束的基本使用
  • EasyExcel(二)导出Excel表自动换行和样式设置
  • 农产品直播带货方案拆解
  • “**H5**” 和 “**响应式**” 是前端开发中常见的术语,但它们的概念和使用场景有所不同
  • 基于EasyExcel实现通用版一对一、一对多、多层嵌套结构数据导出并支持自动合并单元格
  • Java堆内存分析
  • maven高级(day15)
  • 计算机组成原理(九):乘法器
  • python【输入和输出】
  • 2024年华为OD机试真题-判断一组不等式是否满足约束并输出最大差-Python-OD统一考试(E卷)
  • 【json】
  • 基于单片机的无线智能窗帘控制器的设计
  • 磁盘满造成业务异常问题排查
  • C++例程:使用I/O模拟IIC接口(6)
  • 58.在 Vue 3 中使用 OpenLayers 绘制点、线、圆、多边形
  • 如何快速上手一个鸿蒙工程
  • c++入门之 命名空间与输入输出
  • GRE技术的详细解释
  • Mysql--基础篇--多表查询(JOIN,笛卡尔积)
  • Java 泛型的用法
  • 人工智能与物联网:智慧城市的未来
  • Python标准库之SQLite3
  • 力扣 二叉树的最大深度
  • Linux_进程间通信_共享内存
  • ubuntu 下生成 core dump
  • 学习HLS.js
  • 2025年华为OD上机考试真题(Java)——判断输入考勤信息能否获得出勤奖
  • 空对象模式