美文网首页
SpringBoot 2 Admin 搭建

SpringBoot 2 Admin 搭建

作者: EdgeE | 来源:发表于2020-06-02 17:53 被阅读0次

搭建 Spring Boot Admin Server

本文采用配合Eureka注册中心来进行服务发现
pom.xml文件如下:

<properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Hoxton.SR5</spring-cloud.version>
        <spring-boot-admin.version>2.2.3</spring-boot-admin.version>
</properties>

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <exclusions><!-- 去掉默认配置 -->
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-log4j2</artifactId>
        </dependency>
<!--        <dependency>-->
<!--            <groupId>org.springframework.boot</groupId>-->
<!--            <artifactId>spring-boot-starter-security</artifactId>-->
<!--        </dependency>-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-server</artifactId>
        </dependency>
</dependencies>

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

bootstrap.yml文件如下:

server:
 port: 7001
spring:
 application:
   name: POLICE-ADMIN
 security:
   user:
     name: "admin"
     password: "admin"
 cloud:
   config:
     enabled: false
eureka:  
 instance:
   preferIpAddress: true
   instance-id: ${spring.cloud.client.ipAddress}:${server.port}
 client:
   serviceUrl:
     defaultZone: http://127.0.0.1:7000/eureka/

在启动类增加@EnableAdminServer注解

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

搭建客户端

客户端增加依赖:

<dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

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

在Client的配置文件配置应用名、端口、向注册中心注册的地址,以及暴露actuator的所有端口。

server:
  port: 8888
  shutdown: graceful
management:
  endpoints:
    web:
      exposure:
        include: '*'
  endpoint:
    health:
      show-details: always
    shutdown:
      enabled: true
    configprops:
      enabled: true
spring:
  application:
    name: CODE-BASE
  lifecycle:
    timeout-per-shutdown-phase: 30s

eureka: ## eureka server
  instance:
    preferIpAddress: true
    instance-id: ${spring.cloud.client.ipAddress}:${server.port}
  client:
    serviceUrl:
      defaultZone: http://127.0.0.1:7000/eureka/

启动工程后,在浏览器输入HTTP://127.0.0.1:7001

相关文章

网友评论

      本文标题:SpringBoot 2 Admin 搭建

      本文链接:https://www.haomeiwen.com/subject/wscpzhtx.html