springboot-admin使用

springboot admin server服务

官方文档
Spring Boot Admin is a application to manage and monitor your Spring Boot Applications. The applications register with our Spring Boot Admin Client (via HTTP) or are discovered using Spring Cloud (e.g. Eureka). The UI is just an AngularJs application on top of the Spring Boot Actuator endpoints.

admin server

  • pom.xml

    
      org.springframework.boot
      spring-boot-starter-web
    
    
      de.codecentric
      spring-boot-admin-server
      1.5.2
    
    
      de.codecentric
      spring-boot-admin-server-ui
      1.5.2
    
    
      org.springframework.boot
      spring-boot-actuator
    

    
      de.codecentric
      spring-boot-admin-server-ui-login
      1.5.2
    
    
      de.codecentric
      spring-boot-admin-starter-client
      1.5.2
    
    
      org.springframework.boot
      spring-boot-starter-security
    
    
      junit
      junit
      3.8.1
      test
    
  

注意client和server的版本,最好保持一致。

  • application.yml
server:
  port: 8081

management:
  context-path: "/actuator"
  security:
    enabled: false
security:
  basic:
    enabled: false

spring:
  application:
    name: "@pom.artifactId@"
  boot:
    admin:
      url: http://localhost:${server.port}
#      username: "${security.user.name}"       #These two are needed so that the client
#      password: "${security.user.password}"   #can register at the protected server api
#      client:
#        metadata:
#          user.name: "${security.user.name}"          #These two are needed so that the server
#          user.password:  "${security.user.password}" #can access the proteceted client endpoints
  jackson:
    serialization:
      indent_output: true
endpoints:
  health:
    sensitive: false

#security:
#  user:
#    name: user
#    password: pass

这里说明下:

management:
  context-path: "/actuator"
  security:
    enabled: false

这个开启下,在控制台方便查看trace等信息。
这里注释掉的是权限信息。

  • bootstrap.java
    启动类
@Configuration
@EnableAutoConfiguration
@SpringBootApplication
@EnableAdminServer

服务启动后,会看到如下

springboot-admin使用_第1张图片
屏幕快照 2017-08-19 下午4.08.03.png

这个时候看到服务已经启动了。

admin client

adminclient也是一个springboot工程

  • application.yml文件
spring:
  application:
    name: bootadmin-client
  boot:
    admin:
      url: http://localhost:8081
      client:
        name: ${spring.application.name}
#        enabled: true
#        metadata:
#          user.name: ${security.user.name}
#          user.password: ${security.user.password}
  jackson:
      serialization:
        indent_output: true
server:
  port: 8002

management:
  context-path: "/actuator"
  security:
    enabled: false
security:
  basic:
    enabled: false
#
#security:
#  user:
#    name: user
#    password: pass

这里废话不多说,直接贴代码。大家自己试下就行了。

有个注意的点是:client的版本的问题,如果不一致,可能会导致注册不上去,如下保证client和server的client的版本一致。

  • pom.xml

    
      de.codecentric
      spring-boot-admin-starter-client
      1.5.2
    
    
      org.springframework.boot
      spring-boot-starter-web
    
    
      org.springframework.boot
      spring-boot-starter-actuator
    
    
      org.springframework.boot
      spring-boot-starter-test
    

  

服务启动后,可以看到,springboot的client已经注册上去了:

屏幕快照 2017-08-19 下午4.15.20.png

当然,这里也可以用eureka或者consul来做服务的注册和发现。即client和server通过eureka或者consul来进行服务的注册和发现。因为两者都是springboot的web项目。

你可能感兴趣的:(springboot-admin使用)