我爱编程

Springboot 连接Eureka注册中心

2018-07-26  本文已影响0人  夜寻

pom.xml

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <!--添加SpingCloud 版本-->
        <spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
    </properties>
        <!--添加健康监控。 并排除默认的log框架 使用log4j2-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</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.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
            <version>2.0.0.RELEASE</version>
        </dependency>

    <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>

application.properties

# 应用名称必传
spring.application.name=spring.application.name=@project.name@-@profileActive@

# 监控不开启鉴权认证(存在一定的风险)
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always

#应用基本信息
info.app.name="@project.name@"
info.app,description= "@project.description@"
info.app.version="@project.version@"

# 应用请求路径 如果存在context.path 则有一些问题 需要注意
server.servlet.context-path=/cloud-admin
# 如果没有contextPath的话这些不用配置
eureka.instance.health-check-url-path=${server.servlet.context-path}/actuator/health
eureka.instance.status-page-url-path=${server.servlet.context-path}/actuator/info

eureka.instance.metadata-map.management.context-path=${server.servlet.context-path}/actuator

# 向erueka注册
eureka.instance.leaseRenewalIntervalInSeconds= 30
eureka.instance.prefer-ip-address=true
eureka.client.registryFetchIntervalSeconds= 15
eureka.client.serviceUrl.defaultZone=http://10.60.110.8:8199/eureka-server/eureka/,http://10.60.110\
  .9:8199/eureka-server/eureka/,http://10.60.110.10:8199/eureka-server/eureka/
  

Application.class

@EnableDiscoveryClient
public class SpringbootadminApplication {

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

actuator存在的一些接口

GET /autoconfig 查看自动配置的使用情况 true
GET /configprops    查看配置属性,包括默认配置   true
GET /beans  查看bean及其关系列表    true
GET /dump   打印线程栈   true
GET /env    查看所有环境变量    true
GET /env/{name} 查看具体变量值 true
GET /health 查看应用健康指标    false
GET /info   查看应用信息(需要自己在application.properties里头添加信息,比如info.contact.email=easonjim@163.com) false
GET /mappings   查看所有url映射   true
GET /metrics    查看应用基本指标    true
GET /metrics/{name} 查看具体指标  true
POST    /shutdown   关闭应用(要真正生效,得配置文件开启endpoints.shutdown.enabled: true) true
GET /trace  查看基本追踪信息
上一篇 下一篇

猜你喜欢

热点阅读