zoukankan      html  css  js  c++  java
  • Spring Boot Admin 服务端

    创建 Spring Boot Admin Server

    创建一个工程名为 hello-spring-cloud-admin 的项目,pom.xml 文件如下:

    <?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>
    
        <parent>
            <groupId>com.snake</groupId>
            <artifactId>hello-spring-cloud-dependencies</artifactId>
            <version>1.0.0-SNAPSHOT</version>
            <relativePath>../hello-spring-cloud-dependencies/pom.xml</relativePath>
        </parent>
    
        <artifactId>hello-spring-cloud-admin</artifactId>
        <packaging>jar</packaging>
    
        <name>hello-spring-cloud-admin</name>
        <url>http://www.snake.com</url>
        <inceptionYear>2018-Now</inceptionYear>
    
        <dependencies>
            <!-- Spring Boot Begin -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-webflux</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-actuator</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
    
            <dependency>
                <groupId>org.jolokia</groupId>
                <artifactId>jolokia-core</artifactId>
            </dependency>
            <dependency>
                <groupId>de.codecentric</groupId>
                <artifactId>spring-boot-admin-starter-server</artifactId>
            </dependency>
            <!-- Spring Boot End -->
    
            <!-- Spring Cloud Begin -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-zipkin</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
            </dependency>
            <!-- Spring Cloud End -->
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <configuration>
                        <mainClass>com.snake.hello.spring.cloud.admin.AdminApplication</mainClass>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </project>
    

    主要增加了 2 个依赖,org.jolokia:jolokia-corede.codecentric:spring-boot-admin-starter-server

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

    其中 spring-boot-admin-starter-server 的版本号为:2.0.0,这里没写版本号是因为我已将版本号托管到 dependencies 项目中

    #Application

    通过 @EnableAdminServer 注解开启 Admin 功能

    package com.snake.hello.spring.cloud.admin;
    
    import de.codecentric.boot.admin.server.config.EnableAdminServer;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
    
    @SpringBootApplication
    @EnableEurekaClient
    @EnableAdminServer
    public class AdminApplication {
        public static void main(String[] args) {
            SpringApplication.run(AdminApplication.class, args);
        }
    }
    

    #application.yml

    设置端口号为:8084

    spring:
      application:
        name: hello-spring-cloud-admin
      zipkin:
        base-url: http://localhost:9411
    
    server:
      port: 8084
    
    management:
      endpoint:
        health:
          show-details: always
      endpoints:
        web:
          exposure:
            # 注意:此处在视频里是 include: ["health", "info"] 但已无效了,请修改
            include: health,info
    
    eureka:
      client:
        serviceUrl:
          defaultZone: http://localhost:8761/eureka/
    

    主要增加了 Spring Boot Admin Server 的相关配置

    management:
      endpoint:
        health:
          show-details: always
      endpoints:
        web:
          exposure:
            # 注意:此处在视频里是 include: ["health", "info"] 但已无效了,请修改
            include: health,info
    

    #测试访问监控中心

    打开浏览器访问:http://localhost:8084 会出现以下界面

    img

    等你看到的时候,想变得有一点点不一样
  • 相关阅读:
    2篇msdn上关于语言的文章
    软件测试常用术语表
    Log4net hello world
    自己动手创建 .NET Framework 语言编译器
    ASPNET一个错误记录错误 1 未能找到元数据文件“C:/windows/assembly/GAC_32/System.EnterpriseServices/2.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServi
    读书笔记之C#的is和as操作符强制类型转换收藏
    SQL Server不允许进行远程连接的解决办法
    经典回顾Class.forName()
    wince初学记录 (1)
    关于asp.net中dataList控件的使用学习记录
  • 原文地址:https://www.cnblogs.com/snake107/p/11920754.html
Copyright © 2011-2022 走看看