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

  • 相关阅读:
    QT4.7.1 + VS2008 + QT Designer开发流程心得
    SharePoint 2010 托管元数据Bug (跟邮件提醒功能相关.小bug,大问题)
    SharePoint 2010 技巧系列: 控制Ribbon菜单权限(SiteActions的例子)
    发布一个SharePoint 2010 工具(复制,移动文件和文件夹)
    SHarePoint 2010 技巧 列验证 (column Validation)
    SharePoint 2010系列: 教你如何创建Internet 站点一 (设计母版页)
    SharePoint2010 技巧系列:快速开发Ribbon
    SharePoint 2010 技巧: 限制People Picker搜索非站点集内的用户
    SharePoint 2010 技巧系列 启用文档库接收邮件功能
    SharePoint 2010 技巧系列: 文档管理的自动分发功能
  • 原文地址:https://www.cnblogs.com/lshan/p/13176205.html
Copyright © 2011-2022 走看看