基于spring boot 四大神器Actuator,通过endpoint暴露出health等信息。

Spring Boot Admin 构建过程


1. spring-boot-admin-server配置

1.1 添加dependency

在insight2-actutor项目pom.xml文件中添加下列dependency

    <dependency>
        <groupId>de.codecentric</groupId>
        <artifactId>spring-boot-admin-server</artifactId>
        <version>1.4.1</version>
    </dependency>
    <dependency>
        <groupId>de.codecentric</groupId>
        <artifactId>spring-boot-admin-server-ui</artifactId>
        <version>1.4.1</version>
    </dependency>

spring-boot-admin-server:作为actutor服务端,负责获取本服务的环境信息,以及接收其他client发送的信息 spring-boot-admin-server-ui:服务的web UI界面

1.2 配置 spring-boot-admin-server

1. 在ActuatorApp文件中添加@EnableAdminServer注解,使得应用支持AdminServer

    @EnableAdminServer
    @EnableAutoConfiguration
    @Configuration
    protected static class ApplicationSecurity extends WebSecurityConfigurerAdapter {}

2. 在application.properties文件中添加如下配置

    #server 服务端口配置
    server.port=8090
    server.session-timeout=300

    #management
    management.context-path=/

    #security 登录帐号&密码
    security.user.name=admin
    security.user.password=admin

    #spring
    spring.boot.admin.url=http://localhost:8090
    spring.boot.admin.auth.usename=admin
    spring.boot.admin.auth.password=admin
    spring.application.name=@project.name@

    #log 日志配置
    logging.level.root=DEBUG
    logging.level.org.springframework.security=DEBUG
    logging.file=./log/insight-admin.log

    #info 设置服务基本信息
    info.build.artifact=@project.artifactId@
    info.build.name=@project.name@
    info.build.description=@project.description@
    info.build.version=@project.version@

2. spring-boot-admin-client配置

2.1 添加dependency
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-client</artifactId>
            <version>1.4.1</version>
        </dependency>
        <dependency>
            <groupId>org.jolokia</groupId>
            <artifactId>jolokia-core</artifactId>
        </dependency>

spring-boot-admin-starter-client:作为actutor客户端,负责获取本服务的环境信息,并发送给服务端(server) jolokia-core:实现通过Web控制系统的日志级别

2.2 配置 spring-boot-admin-client

1. 在application.properties文件中添加如下配置

    #actuator
    spring.application.name=@project.name@
    #设置client提交信息的url,一般为server端的端口地址
    spring.boot.admin.url=http://127.0.0.1:8090
    management.context-path=/management
    #endpoints选择暴露的信息如health,env等
    endpoints.sensitive=false
    #如果没有数据库,不关闭会由于得不到而出错
    management.health.db.enabled=false
    #关闭security,当信息由于安全被拦截时使用。true:启用,false:关闭
    management.security.enabled=false

results matching ""

    No results matching ""