springboot admin 使用

1.准备server端

新建项目,引入

 springboot 版本 

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.5.6</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

 引入  

<properties>
        <java.version>1.8</java.version>
        <spring-boot-admin.version>2.5.3</spring-boot-admin.version>

    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- https://mvnrepository.com/artifact/de.codecentric/spring-boot-admin-server -->
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-server</artifactId>
            <version>${spring-boot-admin.version}</version>
        </dependency>
        <!-- security 权限 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
    </dependencies>

加上注解

添加springboot security        SecuritySecureConfig

package cn.expkw.springboot_admin;

import de.codecentric.boot.admin.server.config.AdminServerProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
import org.springframework.security.web.csrf.CookieCsrfTokenRepository;

/**
 * @Classname SecuritySecureConfig
 * @Description TODO
 * @Date 2021/11/15 9:39
 * @Created by wangjun
 */
@Configuration
public class SecuritySecureConfig extends WebSecurityConfigurerAdapter {

    private final String adminContextPath;

    public SecuritySecureConfig(AdminServerProperties adminServerProperties) {
        this.adminContextPath = adminServerProperties.getContextPath();
    }

    @Override
    public void configure(HttpSecurity http) throws Exception {

        // 登录成功处理类
        SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
        successHandler.setTargetUrlParameter("redirectTo");
        successHandler.setDefaultTargetUrl(adminContextPath + "/");

        http.authorizeRequests()
                .antMatchers(adminContextPath + "/assets/**").permitAll()
                //登录页面允许访问
                .antMatchers(adminContextPath + "/login").permitAll()
                //其他所有请求需要登录
                .anyRequest().authenticated()
                .and()
                //登录页面配置替换security默认页面
                .formLogin().loginPage(adminContextPath + "/login").successHandler(successHandler).and()

                .logout().logoutUrl(adminContextPath + "/logout").and()
                .httpBasic().and()
                .csrf()
                .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
                .ignoringAntMatchers(
                        "/instances",
                        "/actuator/**"
                );
    }
}

配置:

server:
  port: 8030


spring:
  application:
    name: spring-boot-admin-server
  #  boot:
#    admin:
#      context-path: monitor
  thymeleaf:
    check-template: false
    check-template-location: false
  security:
    user:
      name: xxxx
      password: pwd@xxxx

Spring Boot Adminhttp://localhost:8033/applications

client 端: 

 添加依赖
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-client</artifactId>
            <version>2.5.3</version>
        </dependency>

配置 

spring:
  application:
    name: admin-client
  boot:
    admin:
      client:
        url: http://localhost:8030
        username: xxxx
        password: pwd@xxxx
server:
  port: 8768

management:
  endpoints:
    web:
      exposure:
        include: '*'
  endpoint:
    health:
      show-details: ALWAYS

2. 增加钉钉通知

(39条消息) Spring Boot Admin 集成自定义监控告警(2.0.1版本)------钉钉机器人_yuancao24的博客-CSDN博客

参:

SpringBootAdmin + SpringSecurity 安全框架完整搭建及测试验证_calvins的专栏-CSDN博客1 相关代码 SpringBoot 版本:2.2.0.RELEASE 服务端:(1)配置文件。server: port: 8000spring: application: name: spring-boot-admin-server security: user: name: admin password: admin(2)pom.xml 依赖<dependencies><dependen..https://blog.csdn.net/zwzwzw0a0s/article/details/106239719

Springboot: Springboot + spring boot admin 监控 spring security权限控制_桂小五爱吃肉的博客-CSDN博客Springboot admin 很好的提供了对Springboot的监控,但是不建议直接将admin整合到已有的项目中。于是我另起一个项目,考虑到不能让所有人都能看到这些数据了,于是引入了spring security。 本次使用的是spring-boot-admin-server:2.0.3 server 和  clent 的关系,client通过http注册到server中,当然...https://blog.csdn.net/qq_25582683/article/details/82895537

猜你喜欢

转载自blog.csdn.net/Allure_LoveU/article/details/121163443