开发手册 欢迎您!
软件开发者资料库

Spring Boot - 管理服务器

Spring Boot管理服务器 - 从简单和简单的步骤学习Spring Boot,从基本到高级概念,包括简介,快速入门,引导,Tomcat部署,构建系统,代码结构,Spring Bean和依赖注入,Runners,应用程序属性,日志记录等示例,构建RESTful Web服务,异常处理,拦截器,Servlet过滤器,Tomcat端口号,Rest模板,文件处理,服务组件,Thymeleaf,使用RESTful Web服务,CORS支持,国际化,调度,启用HTTPS,Eureka服务器,服务注册Eureka,Zuul代理服务器和路由,Spring云配置服务器,Spring云配置客户端,执行器,管理服务器,管理客户端,启用Swagger2,创建Docker镜像,跟踪微服务日志,Flyway数据库,发送电子邮件,Hystrix,Web套接字,批处理服务,Apache Kafka的Spring,Twilio,单元测试用例,静止控制器单元测试,数据库处理,保护Web A.应用程序,带有JWT的OAuth2,Google云端平台,Google OAuth2登录。

使用Spring Boot Actuator Endpoint监控应用程序有点困难.因为,如果您有'n'个应用程序,则每个应用程序都有单独的执行器端点,从而使监控变得困难. Spring Boot Admin Server是一个用于管理和监控您的微服务应用程序的应用程序.

为了处理这种情况,CodeCentric Team提供了一个Spring Boot Admin UI来管理和监控所有Spring Boot应用程序执行器一个地方的端点.

为了构建Spring Boot管理服务器,我们需要在构建配置文件中添加以下依赖项.

Maven用户可以在pom.xml文件中添加以下依赖项 :

   de.codecentric   spring-boot-admin-server   1.5.5   de.codecentric   spring-boot-admin-server-ui   1.5.5

Gradle用户可以在build.gradle文件中添加以下依赖项 :

compile group: 'de.codecentric', name: 'spring-boot-admin-server', version: '1.5.5'compile group: 'de.codecentric', name: 'spring-boot-admin-server-ui', version: '1.5.5'

在主Spring Boot应用程序类文件中添加@EnableAdminServer注释. @EnableAdminServer注释用于使您的管理服务器监视所有其他微服务.

package com.it1352.adminserver; import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import de.codecentric.boot.admin.config.EnableAdminServer;@SpringBootApplication@EnableAdminServerpublic class AdminserverApplication {      public static void main(String[] args) {      SpringApplication.run(AdminserverApplication.class, args);   }}

现在,在application.properties文件中定义server.port和application name,显示 : 去;

server.port = 9090spring.application.name = adminserver

对于YAML用户,使用以下属性在application.yml文件中定义端口号和应用程序名称.

server:   port: 9090spring:   application:      name: adminserver

构建配置文件如下所示.

对于Maven用户 -  pom.xml

      4.0.0   com.IT屋   adminserver   0.0.1-SNAPSHOT   jar   adminserver   Demo project for Spring Boot         org.springframework.boot      spring-boot-starter-parent      1.5.9.RELEASE                   UTF-8      UTF-8      1.8                     org.springframework.boot         spring-boot-starter                     de.codecentric         spring-boot-admin-server         1.5.5                           de.codecentric         spring-boot-admin-server-ui         1.5.5                     org.springframework.boot         spring-boot-starter-test         test                                       org.springframework.boot            spring-boot-maven-plugin                     

对于Gradle用户 -  build.gradle文件

buildscript {   ext {      springBootVersion = '1.5.9.RELEASE'   }   repositories {      mavenCentral()   }   dependencies {      classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")   }}apply plugin: 'java'apply plugin: 'eclipse'apply plugin: 'org.springframework.boot'group = 'com.it1352'version = '0.0.1-SNAPSHOT'sourceCompatibility = 1.8repositories {      mavenCentral()}dependencies {   compile('org.springframework.boot:spring-boot-starter')   compile group: 'de.codecentric', name: 'spring-boot-admin-server', version: '1.5.5'   compile group: 'de.codecentric', name: 'spring-boot-admin-server-ui', version: '1.5.5'      testCompile('org.springframework.boot:spring-boot-starter-test')}

你可以创建一个可执行的JAR文件,然后运行Spring使用以下Maven或Gradle命令启动应用程序 :

对于Maven,使用此处显示的命令 :

mvn clean install

在"BUILD SUCCESS"之后,您可以在目标目录下找到JAR文件.

对于Gradle,使用此处显示的命令 :

gradle clean build

在"BUILD SUCCESSFUL"之后,您可以在build/libs目录下找到JAR文件.

现在,使用下面给出的命令运行JAR文件 :

java -jar 

现在,应用程序已在Tomcat端口9090上启动,如下所示 :

Tomcat端口9090输出

现在从网络浏览器点击以下网址,查看管理服务器用户界面.

http://localhost:9090/

网页浏览器管理服务器UI