Customize your own Eureka management interface

Time:2020-10-27

EurekaThe interface of the server can be customized, and the method is relatively simple. Let’s take a look at the modification method.

In some companies, the service registry interface may need to be completely customized and carry some company features and elements. If so, the contents of this chapter can help you, and the effect can be seen in the open Eureka server service that I have exposed.

Create Eureka server project

useIDEADevelopment tools create aSpringBootProject, inpom.xmlAdd dependencies as follows:

<properties>
  <java.version>1.8</java.version>
  <spring-cloud.version>Hoxton.RC2</spring-cloud.version>
</properties>

<dependencies>
  <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-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>
  </dependencies>
</dependencyManagement>

Enable Eureka server

We are starting the classXxxApplicationuse@EnableEurekaServerComments to enableEurekaThe functions of the management end are as follows:

/**
 *Customize Eureka server management interface
 *
 *@ author Hengyu youth
 */
@SpringBootApplication
@EnableEurekaServer
public class CustomizeEurekaManagePageApplication {

    public static void main(String[] args) {
        SpringApplication.run(CustomizeEurekaManagePageApplication.class, args);
    }

}

Configuration services

Next we’re inapplication.ymlAdd in configuration fileEurekaThe configuration information is as follows:

spring:
  application:
    name: customize-eureka-manage-page
#Eureka configuration
eureka:
  client:
    service-url:
      defaultZone: http://127.0.0.1:${server.port}/eureka/
    fetch-registry: false
    register-with-eureka: false

server:
  port: 10000

Custom page

stayspring-cloud-netflix-eureka-server-xx.xx.xx.jarWe can find it in the dependency filetempaltes.eurekaThe structure of the directory is shown in the following figure:

Customize your own Eureka management interface

templates.eurekaIn the directoryErueka ServerManage the template file of the page. We can copy the template file to the current projectresources/templates/eurekaDirectory, and then customize the interface content.

  • header.ftlh: top menu navigation template page
  • lastn.ftlh: service registration record template page
  • navbar.ftlh: Homepage navigation bar information template page
  • status.ftlh: the basic status template page of the server where the service is located

We found itnavbar.ftlhFile, this file containsEureka ServerDisplay system information, service registration list, service server basic information display page on the home pageSystem StatusThe first in the categorytableAdd a line of information as follows:

<tr>
  <td>Young programmer</td>
  <td><img width="400px"/></td>
</tr>

View effects

Let’s start or restart this project, visit http://127.0.0.1 : 10000, the viewing effect is shown in the following figure:

Customize your own Eureka management interface

summary

By amendmenttemplates.eurekaWe can complete the files under the directoryEureka ServerThe user-defined operation of the interface can completely customize the content of the page, and the heart will follow the action. Hurry up~

Code example

This article sample source code can be obtained through the following ways, the directory iscustomize-eureka-manage-page

  • Gitee:https://gitee.com/hengboy/spr…

Customize your own Eureka management interface

Author’s personal blog
Using the open source framework apiboot to help you become an API interface service architect

Recommended Today

Server security settings batch processing

The first one is more complete, and the first one is recommended Copy codeThe code is as follows: @ECHO OFF CLS TITLE SERVER SAFE SETUP PRO COLOR 0A echo y|cacls.exe C:\ /p Administrators:f system:f “network service”:r echo y|cacls.exe D:\ /p Administrators:f system:f servU:f “network service”:r echo y|cacls.exe E:\ /p Administrators:f system:f servU:f “network service”:r echo […]