zoukankan      html  css  js  c++  java
  • SpringBoot admin

    版本:

        <java.version>1.8</java.version>

       <spring-cloud.version>Greenwich.SR6</spring-cloud.version>  (admin server 不需要)

    依赖:

      

        <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>
                <version>2.1.5</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-security</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-actuator</artifactId>
            </dependency>
          
        </dependencies>
    

    主类:

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

    添加配置类: springcloud升级到2.x后Eureka安全配置与1.x有部分变动,新版本的security默认开启csrf了,这里我们先关掉它,否则 服务端注册不上

    新建一个配置类:

    复制代码
    @EnableWebSecurity
    @Configuration
    public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            //关闭csrf
            http.csrf().disable();
            //开启认证
             http.authorizeRequests().anyRequest().authenticated().and().httpBasic();
        }
    }
    复制代码

    配置文件: application.yml

    server:
      port: 9000
    #需要导入spring-boot-starter-security
    #为admin server 添加一个认证,当访问localhost:8761会要求验证
    management:
      endpoints:
        web:
          exposure:
            include: '*'
      endpoint:
        health:
          show-details: always
    spring:
      application:
        name: micro-admin
      security: #安全配置
        basic:
         enabled: true
        user:
          name: root
          password: root

    #####################   至此 , admin server 搭建完毕 ########################

    下面是使用:

    依赖:

      

    <dependency>
                <groupId>de.codecentric</groupId>
                <artifactId>spring-boot-admin-starter-client</artifactId>
                <version>2.1.5</version>
     </dependency>

    application.yml:

    spring:
      application:
        name: MICRO-CLENT1-USER
      boot:
        admin:
          client:
            url:  http://root:root@localhost:9000
        
    management:
      endpoints:
        web:
          exposure:
            include: '*'
      endpoint:
        health: #健康检测 查看 http://localhost:8761/actuator/health
          show-details: always

    或者 application.properties

    eureka.client.service-url.defaultZone = http://root:root@192.168.25.140:8761/eureka/,http://root:root@192.168.25.141:8761/eureka/
    #spring.boot.admin.client.url = http://root:root@192.168.25.143:9000
    spring.boot.admin.client.url = http://192.168.25.143:9000
    spring.boot.admin.client.username=root
    spring.boot.admin.client.password=root
    management.endpoints.web.exposure.include =* management.endpoint.health.show-details= ALWAYS
    eureka.instance.prefer-ip-address = true
    spring.boot.admin.client.instance.service-base-url = http://192.168.18.129:7089 //自动申明IP



    check:

      http://127.0.0.1:9000/#/applications

  • 相关阅读:
    Windows 2008 server + IIS 7 设置身份模拟(ASP.NET impersonation)
    记录windows操作系统启动日志
    C# 重启计算机的问题
    AcWing 1086 恨7不是妻
    AcWing 1084. 数字游戏 II
    AcWing 1083. Windy数
    golang学习笔记 生成JSON及解析JSON 清明
    WEB前端底层知识之浏览器是如何工作的(2)渲染引擎
    ASP.NET MVC Razor 输出没有编码的HTML字符串
    ext.grid的配置属性和方法
  • 原文地址:https://www.cnblogs.com/lshan/p/13176205.html
Copyright © 2011-2022 走看看