spring-boot-admin笔记

news2024/10/6 22:22:31

spring-boot-admin笔记

本篇教程是基于springboot 2.3.8.RELEASE版本
和spring-boot-admin-dependencies 2.3.0版本

搭建spring-boot-admin的server端app

pom配置

<?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">
    <modelVersion>4.0.0</modelVersion>
    <name>dftjk</name>
    <description>Demo project for Spring Boot</description>


    <groupId>cn.mt</groupId>
    <artifactId>dftjk</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <java.version>1.8</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <spring-boot.version>2.3.8.RELEASE</spring-boot.version>

    </properties>

    <dependencies>

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

        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-server</artifactId>
        </dependency>

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <dependency>
                <groupId>de.codecentric</groupId>
                <artifactId>spring-boot-admin-dependencies</artifactId>
                <version>2.3.0</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${spring-boot.version}</version>
                <configuration>
                    <mainClass>cn.mt.dft.App</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <id>repackage</id>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

启动类配置

package cn.mt.dft;


import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.scheduling.annotation.EnableScheduling;


@EnableAdminServer
@SpringBootApplication
public class App {
    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }
}

内置访问认证配置

package cn.mt.dft;

import de.codecentric.boot.admin.server.config.AdminServerProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
import org.springframework.security.web.csrf.CookieCsrfTokenRepository;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;

import java.util.UUID;

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    private final AdminServerProperties adminServerProperties;

    public SecurityConfig(AdminServerProperties adminServerProperties) {
        this.adminServerProperties = adminServerProperties;
    }


    @Override
    protected void configure(HttpSecurity http) throws Exception {
        SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
        successHandler.setTargetUrlParameter("redirectTo");
        successHandler.setDefaultTargetUrl(this.adminServerProperties.path("/"));

        http.authorizeRequests(
                (authorizeRequests) -> authorizeRequests.antMatchers(this.adminServerProperties.path("/assets/**")).permitAll()
                        .antMatchers(this.adminServerProperties.path("/login")).permitAll().anyRequest().authenticated()
        ).formLogin(
                (formLogin) -> formLogin.loginPage(this.adminServerProperties.path("/login")).successHandler(successHandler).and()
        ).logout((logout) -> logout.logoutUrl(this.adminServerProperties.path("/logout"))).httpBasic(Customizer.withDefaults())
                .csrf((csrf) -> csrf.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
                        .ignoringRequestMatchers(
                                new AntPathRequestMatcher(this.adminServerProperties.path("/instances"),
                                        HttpMethod.POST.toString()),
                                new AntPathRequestMatcher(this.adminServerProperties.path("/instances/*"),
                                        HttpMethod.DELETE.toString()),
                                new AntPathRequestMatcher(this.adminServerProperties.path("/actuator/**"))
                        ))
                .rememberMe((rememberMe) -> rememberMe.key(UUID.randomUUID().toString()).tokenValiditySeconds(1209600));

    }
}

application.yml配置

server:
  port: 8814
  compression:
    enabled: true  # 开启Gzip压缩,响应数据超过1kb时触发gzip自动压缩,以提高前端响应时间
    min-response-size: 1KB
  servlet:
    session:
      timeout: PT30M  #默认会话过期时间30分钟
    encoding:
      enabled: true
      charset: UTF-8
      force: true
  tomcat:
    uri-encoding: UTF-8




# http://localhost:8811/actuator/info 查看info端点会返还自定义的info信息
info:
  appname: dftjk
  ver: 1.0

# http://localhost:8811/actuator 查看暴露的所有可访问的端点
# http://localhost:8811/actuator/health 查看health端点
management:
  endpoints:
    web:
      exposure:

        include: [health,info,mappings] #开启health,info,mappings端点, 若配置*表示暴露所有端点
  endpoint:
    health:
      show-details: always # health端点展示详细信息



spring:
  security:
    user:
      name: root
      password: root
  application:
    name: dftjk
  servlet:
    multipart:
      max-file-size: 50MB  #单个文件的最大上限
      max-request-size: 200MB  #单个请求的文件总大小限制
      location: ${user.home}/.${spring.application.name}/tempDir





logging:
  file:
    #最终的存储路径是:  系统用户目录/.应用名称/logs/端口号/spring.log
    path: ${user.home}/.${spring.application.name}/logs/${server.port}
    max-history: 7
    max-size: 10MB
  pattern:
    console: "%date  %clr(%level) [${PID}]  [%thread] [%magenta(%X{traceId})] %cyan(%logger{10}) [%file : %line] %msg%n"
    file: "%date %level [${PID}]   [%thread] [%X{traceId}] %logger{10} [%file : %line] %msg%n"



测试启动后的访问效果

  1. 访问localhost:8814
    请添加图片描述

登录密码是 root / root

  1. 登录进入主页
    请添加图片描述

因为此时还没有服务注册到spring-boot-admin-server,所以这里暂时没有应用记录

搭建spring-boot-admin的client端app

部分pom配置

 <dependencies>
		<dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
</dependencies>
<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <dependency>
                <groupId>de.codecentric</groupId>
                <artifactId>spring-boot-admin-dependencies</artifactId>
                <version>2.3.0</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

        </dependencies>
    </dependencyManagement>

部分application.yml配置

# http://localhost:8811/actuator/info 查看info端点会返还自定义的info信息
info:
  appname: dft
  ver: 1.0

# http://localhost:8811/actuator 查看暴露的所有可访问的端点
# http://localhost:8811/actuator/health 查看health端点
management:
  endpoints:
    web:
      exposure:
        include: '*'
#        include: [health,info,mappings] #开启health,info,mappings端点, 若配置*表示暴露所有端点
  endpoint:
    health:
      show-details: always # health端点展示详细信息
    shutdown:
      enabled: true #允许优雅停机
logging:
  file:
    #最终的存储路径是:  系统用户目录/.应用名称/logs/端口号/spring.log
    path: ${user.home}/.${spring.application.name}/logs/${server.port}
    max-history: 7
    max-size: 10MB
  pattern:
    console: "%date  %clr(%level) [${PID}]  [%thread] [%magenta(%X{traceId})] %cyan(%logger{10}) [%file : %line] %msg%n"
    file: "%date %level [${PID}]   [%thread] [%X{traceId}] %logger{10} [%file : %line] %msg%n"


spring:
  application:
    name: dft
  boot:
    admin:
      client:
        enabled: true #启用spring-boot-admin
        url: http://127.0.0.1:8814 #服务器端的访问地址
        username: root #服务器端的访问账号
        password: root #服务器端的访问密码

测试启动后的spring-boot-admin效果

  1. 启动刚刚建的client服务,然后访问spring-boot-admin服务器端-访问localhost:8814
    请添加图片描述

  2. 查看应用列表
    请添加图片描述

  3. 查看应用详情
    请添加图片描述

  4. 查看实时日志
    请添加图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/882597.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Java课题笔记~ 数据提交的方式

前四种数据注入的方式&#xff0c;会自动进行类型转换。但无法自动转换日期类型。 &#xff08;1&#xff09;单个数据&#xff08;基本数据类型&#xff09;注入 在方法中声明一个和表单提交的参数名称相同的参数&#xff0c;由框架按照名称直接注入。 &#xff08;2&#x…

GD32F103的DAC1

GD32F103的DAC1采用定时器1触发&#xff0c;DMA传输&#xff0c;将数据转换为电压输出到PA5引脚。 GD32F103的DAC为12位DA转换器,可以将12位的数据转换为电压,从外部引脚上输出; DAC_OUT0映射到PA4,DAC_OUT1映射到PA5; DACx引脚上的模拟输出电压: DACoutput DAC_DO * Vref/4…

Git命令详解

1 常用命令 1&#xff09;初始化本地仓库 git init <directory> 是可选的&#xff0c;如果不指定&#xff0c;将使用当前目录。 2&#xff09;克隆一个远程仓库 git clone <url> 3&#xff09;添加文件到暂存区 git add <file> 要添加当前目录中的所…

概念解析 | 长尾分布:从无处不在的‘少数派’中挖掘价值

注1:本文系“概念解析”系列之一,致力于简洁清晰地解释、辨析复杂而专业的概念。本次辨析的概念是:长尾分布(Long-Tail Distribution)。 揭秘长尾分布:从无处不在的‘少数派’中挖掘价值 What is a Long Tail Distribution? (Definition & Example) - Statology 一、背…

Neo4j的使用场景_以及Windows版安装_欺诈检测_推荐_知识图谱---Neo4j图数据库工作笔记0003

可以看到使用场景,比如欺诈检测, 要建立图谱,才能进行,欺诈人员检测 可以看到图谱的各种应用场景 然后推荐引擎也需要,可以看到 在金融,旅行,求职招聘,保健,服务,媒体娱乐,都可以进行推荐 然后还有知识图谱 身份访问管理,这里,可以进行安全管理,可以挖掘出潜在关系,分析, 某…

Android学习之路(4) UI控件之Button (按钮)与 ImageButton (图像按钮)

本节引言&#xff1a; 今天给大家介绍的Android基本控件中的两个按钮控件&#xff0c;Button普通按钮和ImageButton图像按钮&#xff1b; 其实ImageButton和Button的用法基本类似&#xff0c;至于与图片相关的则和后面ImageView相同&#xff0c;所以本节 只对Button进行讲解&am…

Spring Security实现办公系统权限控制(含认证和授权流程、底层分析)

一、Spring Security介绍 1、Spring Security简介 Spring 是非常流行和成功的 Java 应用开发框架&#xff0c;Spring Security 正是 Spring 家族中的成员。Spring Security 基于 Spring 框架&#xff0c;提供了一套 Web 应用安全性的完整解决方案。 正如你可能知道的关于安全…

stop job is running for Advanced key-value store

今天虚拟机磁盘撑满了&#xff0c;本来还能凑合运行&#xff0c;结果重启了下&#xff0c;就报了这个 stop job is running for Advanced key-value store (1min 59s / no limit) 解决方式很简单&#xff0c; 1、虚拟机关电源&#xff0c;任务管理器&#xff0c;关闭VM&#x…

Spring Security用户授权

用户认证在上一篇用户认证 用户授权 总体流程&#xff1a; 在SpringSecurity中&#xff0c;会使用默认的FilterSecurityInterceptor来进行权限校验。在FilterSecurityInterceptor中会从SecurityContextHolder获取其中的Authentication&#xff0c;然后获取其中的权限信息。…

Linux(进程控制)

进程控制 进程创建fork函数初识fork函数返回值写时拷贝fork常规用法fork调用失败的原因 进程终止进程退出码进程常见退出方法 进程等待进程等待必要性获取子进程status进程等待的方法 阻塞等待与非阻塞等待阻塞等待非阻塞等待 进程替换替换原理替换函数函数解释命名理解 做一个…

Java 并发编程--Volatile、Synchronized和锁

一、Java内存模型&#xff08;JMM&#xff09; Java内存模型即Java Memory Model&#xff0c;简称JMM。JMM定义了Java 虚拟机(JVM)在计算机内存(RAM)中的工作方式。JVM是整个计算机虚拟模型&#xff0c;所以JMM是隶属于JVM的。 从抽象的角度来看&#xff0c;JMM定义了线程和主…

react-native-webview使用postMessage后H5不能监听问题(iOS和安卓的兼容问题)

/* 监听rn消息 */ const eventListener nativeEvent > {//解析数据actionType、extraconst {actionType, extra} nativeEvent.data && JSON.parse(nativeEvent.data) || {} } //安卓用document&#xff0c;ios用window window.addEventListener(message, eventLis…

verilog学习笔记6——锁存器和触发器

文章目录 前言一、锁存器1、基本SR锁存器——或非门实现2、基本SR锁存器——与非门实现3、门控SR锁存器4、门控D锁存器 二、触发器1、 电平触发的RS触发器/同步SR触发器2、电平触发的D触发器/D型锁存器3、边沿触发的D触发器4、脉冲触发的RS触发器 三、边沿触发、脉冲触发、电平…

LVS-DR集群(一台LVS,一台CIP,两台web,一台NFS)的构建

一.构建环境 1.五台关闭防火墙&#xff0c;关闭selinux&#xff0c;拥有固定IP&#xff0c;部署有http服务的虚拟机&#xff0c;LVS设备下载ipvsadm工具&#xff0c;NFS 设备需要下载rpcbind和nfs-utils 2.实现功能 3.ipvsadm命令部分参数介绍 二.配置和测试 1.LVS设备 &…

re学习(32)【绿城杯2021】babyvxworks(浅谈花指令)

链接&#xff1a;https://pan.baidu.com/s/1msA5EY_7hoYGBEema7nWwA 提取码&#xff1a;b9xf wp:首先找不到main函数&#xff0c;然后寻找特殊字符串&#xff0c; 交叉引用 反汇编 主函数在sub_3D9当中&#xff0c;但是IDA分析错了 分析错误后&#xff0c;删除函数 创建函数 操…

Python学习笔记_基础篇(六)_Set集合,函数,深入拷贝,浅入拷贝,文件处理

1、Set基本数据类型 a、set集合&#xff0c;是一个无序且不重复的元素集合 class set(object):"""set() -> new empty set objectset(iterable) -> new set objectBuild an unordered collection of unique elements."""def add(self, *a…

人工智能时代的科学探索 | 《自然》评述

人工智能(AI)正越来越多地融入科学发现&#xff0c;以增强和加速研究&#xff0c;帮助科学家提出假设、设计实验、收集和解释大型数据集&#xff0c;并获得仅靠传统科学方法可能无法实现的洞察力。 过去十年间&#xff0c;AI取得了巨大的突破。其中就包括自监督学习和几何深度学…

LabVIEW开发最小化5G系统测试平台

LabVIEW开发最小化5G系统测试平台 由于具有大量存储能力和数据的应用程序的智能手机的激增&#xff0c;当前一代产品被迫提高其吞吐效率。正交频分复用由于其卓越的品质&#xff0c;如单抽头均衡和具有成本效益的实施&#xff0c;现在被广泛用作物理层技术。这些好处是以严格的…

Image Super-Resolution Using Deep Convolutional Networks-SRCNN

Some words&#xff1a; 这里是一些阅读文章的笔记&#xff0c;这篇文章是第一篇将深度学习应用于超分领域的文章&#xff0c;具有较为重要的意义。 &#xff08;一&#xff09;Abstract&#xff1a; 我们提出一个对于单图像超分的深度学习方法&#xff0c;端到端地学习高低分…

C语言编程:最小二乘法拟合直线

本文研究通过C语言实现最小二乘法拟合直线。 文章目录 1 引入2 公式推导3 C语言代码实现4 测试验证5 总结 1 引入 最小二乘法&#xff0c;简单来说就是根据一组观测得到的数值&#xff0c;寻找一个函数&#xff0c;使得函数与观测点的误差的平方和达到最小。在工程实践中&…