SpringBoot四大神器之Actuator的使用小结


Spring Boot有四大神器,分别是auto-configuration、starters、cli、actuator,本文主要讲actuator。actuator是spring boot提供的对应用系统的自省和监控的集成功能,可以对应用系统进行配置查看、相关功能统计等。

spring-boot-starter-actuator模块的实现对于实施微服务的中小团队来说,可以有效地减少监控系统在采集应用指标时的开发量。当然,它也并不是万能的,有时候我们也需要对其做一些简单的扩展来帮助我们实现自身系统个性化的监控需求。下面,在本文中,我们将详解的介绍一些关于spring-boot-starter-actuator模块的内容,包括它的原生提供的端点以及一些常用的扩展和配置方式。

使用actuator

添加依赖

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>

主要暴露的功能

HTTP方法 路径 描述 鉴权
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 查看应用信息 false
GET /mappings 查看所有url映射 true
GET /metrics 查看应用基本指标 true
GET /metrics/{name} 查看具体指标 true
POST /shutdown 关闭应用 true
GET /trace 查看基本追踪信息 true

/autoconfig

{
  "positiveMatches": {
    "AuditAutoConfiguration.AuditEventRepositoryConfiguration": [
      {
        "condition": "OnBeanCondition",
        "message": "@ConditionalOnMissingBean (types: org.springframework.boot.actuate.audit.AuditEventRepository; SearchStrategy: all) found no beans"
      }
    ]
  },
  "negativeMatches": {
    "CacheStatisticsAutoConfiguration": [
      {
        "condition": "OnBeanCondition",
        "message": "@ConditionalOnBean (types: org.springframework.cache.CacheManager; SearchStrategy: all) found no beans"
      }
    ]
  }
}

/configprops

{
  "management.health.status.CONFIGURATION_PROPERTIES": {
    "prefix": "management.health.status",
    "properties": {
      "order": null
    }
  },
  "multipart.CONFIGURATION_PROPERTIES": {
    "prefix": "multipart",
    "properties": {
      "enabled": false,
      "maxRequestSize": "10Mb",
      "location": null,
      "fileSizeThreshold": "0",
      "maxFileSize": "1Mb"
    }
  },
  "environmentEndpoint": {
    "prefix": "endpoints.env",
    "properties": {
      "id": "env",
      "enabled": true,
      "sensitive": true
    }
  }
}

/beans

[
  {
    "context": "application:8080",
    "parent": null,
    "beans": [
      {
        "bean": "appMain",
        "scope": "singleton",
        "type": "com.xixicat.AppMain$$EnhancerBySpringCGLIB$$29382b14",
        "resource": "null",
        "dependencies": [ ]
      },
      {
        "bean": "videoInfoMapper",
        "scope": "singleton",
        "type": "com.xixicat.dao.VideoInfoMapper",
        "resource": "file [/Users/xixicat/workspace/video-uber/target/classes/com/xixicat/dao/VideoInfoMapper.class]",
        "dependencies": [
          "sqlSessionFactory"
        ]
      }
    ]
  }
]

/dump

[
  {
    "threadName": "Signal Dispatcher",
    "threadId": 4,
    "blockedTime": -1,
    "blockedCount": 0,
    "waitedTime": -1,
    "waitedCount": 0,
    "lockName": null,
    "lockOwnerId": -1,
    "lockOwnerName": null,
    "inNative": false,
    "suspended": false,
    "threadState": "RUNNABLE",
    "stackTrace": [ ],
    "lockedMonitors": [ ],
    "lockedSynchronizers": [ ],
    "lockInfo": null
  },
  {
    "threadName": "Reference Handler",
    "threadId": 2,
    "blockedTime": -1,
    "blockedCount": 217,
    "waitedTime": -1,
    "waitedCount": 9,
    "lockName": "java.lang.ref.Reference$Lock@45de945",
    "lockOwnerId": -1,
    "lockOwnerName": null,
    "inNative": false,
    "suspended": false,
    "threadState": "WAITING",
    "stackTrace": [
      {
        "methodName": "wait",
        "fileName": "Object.java",
        "lineNumber": -2,
        "className": "java.lang.Object",
        "nativeMethod": true
      },
      {
        "methodName": "wait",
        "fileName": "Object.java",
        "lineNumber": 503,
        "className": "java.lang.Object",
        "nativeMethod": false
      },
      {
        "methodName": "run",
        "fileName": "Reference.java",
        "lineNumber": 133,
        "className": "java.lang.ref.Reference$ReferenceHandler",
        "nativeMethod": false
      }
    ],
    "lockedMonitors": [ ],
    "lockedSynchronizers": [ ],
    "lockInfo": {
      "className": "java.lang.ref.Reference$Lock",
      "identityHashCode": 73263429
    }
  }
]

/env

{
 profiles: [],
 server.ports: {
  local.server.port: 8080
 },
 servletContextInitParams: {},
 systemProperties: {
  java.runtime.name: "Java(TM) SE Runtime Environment",
   sun.boot.library.path: "/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre/lib",
   java.vm.version: "24.79-b02",
   gopherProxySet: "false",
   maven.multiModuleProjectDirectory: "/Users/xixicat/workspace/video-uber",
   java.vm.vendor: "Oracle Corporation",
   java.vendor.url: "http://java.oracle.com/",
   guice.disable.misplaced.annotation.check: "true",
   path.separator: ":",
   java.vm.name: "Java HotSpot(TM) 64-Bit Server VM",
   file.encoding.pkg: "sun.io",
   user.country: "CN",
   sun.java.launcher: "SUN_STANDARD",
   sun.os.patch.level: "unknown",
   PID: "763",
   java.vm.specification.name: "Java Virtual Machine Specification",
   user.dir: "/Users/xixicat/workspace/video-uber",
   java.runtime.version: "1.7.0_79-b15",
   java.awt.graphicsenv: "sun.awt.CGraphicsEnvironment",
   java.endorsed.dirs: "/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre/lib/endorsed",
   os.arch: "x86_64",
   java.io.tmpdir: "/var/folders/tl/xkf4nr61033gd6lk5d3llz080000gn/T/",
   line.separator: " ",
   java.vm.specification.vendor: "Oracle Corporation",
   os.name: "Mac OS X",
   classworlds.conf: "/Users/xixicat/devtool/maven-3.3.3/bin/m2.conf",
   sun.jnu.encoding: "UTF-8",
   spring.beaninfo.ignore: "true",
   java.library.path: "/Users/xixicat/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.",
   java.specification.name: "Java Platform API Specification",
   java.class.version: "51.0",
   sun.management.compiler: "HotSpot 64-Bit Tiered Compilers",
   os.version: "10.10.5",
   user.home: "/Users/xixicat",
   user.timezone: "Asia/Shanghai",
   java.awt.printerjob: "sun.lwawt.macosx.CPrinterJob",
   file.encoding: "UTF-8",
   java.specification.version: "1.7",
   java.class.path: "/Users/xixicat/devtool/maven-3.3.3/boot/plexus-classworlds-2.5.2.jar",
   user.name: "xixicat",
   java.vm.specification.version: "1.7",
   sun.java.command: "org.codehaus.plexus.classworlds.launcher.Launcher spring-boot:run",
   java.home: "/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre",
   sun.arch.data.model: "64",
   user.language: "zh",
   java.specification.vendor: "Oracle Corporation",
   awt.toolkit: "sun.lwawt.macosx.LWCToolkit",
   java.vm.info: "mixed mode",
   java.version: "1.7.0_79",
   java.ext.dirs: "/Users/xixicat/Library/Java/Extensions:/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre/lib/ext:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java",
   sun.boot.class.path: "/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre/lib/sunrsasign.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre/classes",
   java.awt.headless: "true",
   java.vendor: "Oracle Corporation",
   maven.home: "/Users/xixicat/devtool/maven-3.3.3",
   file.separator: "/",
   LOG_EXCEPTION_CONVERSION_WORD: "%wEx",
   java.vendor.url.bug: "http://bugreport.sun.com/bugreport/",
   sun.io.unicode.encoding: "UnicodeBig",
   sun.cpu.endian: "little",
   sun.cpu.isalist: ""
 },
 systemEnvironment: {
  TERM: "xterm-256color",
  ZSH: "/Users/xixicat/.oh-my-zsh",
  GVM_BROKER_SERVICE: "http://release.gvm.io",
  GRIFFON_HOME: "/Users/xixicat/.gvm/griffon/current",
  JAVA_MAIN_CLASS_763: "org.codehaus.plexus.classworlds.launcher.Launcher",
  JAVA_HOME: "/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home",
  SHLVL: "1",
  MAVEN_CMD_LINE_ARGS: " spring-boot:run",
  __CF_USER_TEXT_ENCODING: "0x1F5:0x19:0x34",
  GROOVY_HOME: "/Users/xixicat/.gvm/groovy/current",
  XPC_FLAGS: "0x0",
  GVM_INIT: "true",
  JBAKE_HOME: "/Users/xixicat/.gvm/jbake/current",
  PWD: "/Users/xixicat/workspace/video-uber",
  GVM_DIR: "/Users/xixicat/.gvm",
  GVM_VERSION: "2.4.3",
  MAVEN_PROJECTBASEDIR: "/Users/xixicat/workspace/video-uber",
  LOGNAME: "xixicat",
  SSH_AUTH_SOCK: "/private/tmp/com.apple.launchd.93xr1duECQ/Listeners",
  SPRINGBOOT_HOME: "/Users/xixicat/.gvm/springboot/current",
  GAIDEN_HOME: "/Users/xixicat/.gvm/gaiden/current",
  LAZYBONES_HOME: "/Users/xixicat/.gvm/lazybones/current",
  OLDPWD: "/Users/xixicat/workspace/video-uber",
  SHELL: "/bin/zsh",
  JBOSSFORGE_HOME: "/Users/xixicat/.gvm/jbossforge/current",
  LC_CTYPE: "zh_CN.UTF-8",
  TMPDIR: "/var/folders/tl/xkf4nr61033gd6lk5d3llz080000gn/T/",
  GVM_SERVICE: "http://api.gvmtool.net",
  GVM_PLATFORM: "Darwin",
  CLASSPATH: ".:/Users/xixicat/.m2/repository/co/paralleluniverse/quasar-core/0.7.2/quasar-core-0.7.2.jar",
  GLIDE_HOME: "/Users/xixicat/.gvm/glide/current",
  PATH: "/Users/xixicat/.gvm/vertx/current/bin:/Users/xixicat/.gvm/springboot/current/bin:/Users/xixicat/.gvm/lazybones/current/bin:/Users/xixicat/.gvm/jbossforge/current/bin:/Users/xixicat/.gvm/jbake/current/bin:/Users/xixicat/.gvm/groovyserv/current/bin:/Users/xixicat/.gvm/groovy/current/bin:/Users/xixicat/.gvm/griffon/current/bin:/Users/xixicat/.gvm/grails/current/bin:/Users/xixicat/.gvm/gradle/current/bin:/Users/xixicat/.gvm/glide/current/bin:/Users/xixicat/.gvm/gaiden/current/bin:/Users/xixicat/.gvm/crash/current/bin:/Users/xixicat/.gvm/asciidoctorj/current/bin:/Users/xixicat/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin:/Users/xixicat/devtool/maven-3.3.3/bin:/Users/xixicat/devtool/gradle-2.6/bin:/Users/xixicat/devtool/android-sdk/platform-tools",
  GRADLE_HOME: "/Users/xixicat/.gvm/gradle/current",
  GROOVYSERV_HOME: "/Users/xixicat/.gvm/groovyserv/current",
  GRAILS_HOME: "/Users/xixicat/.gvm/grails/current",
  USER: "xixicat",
  LESS: "-R",
  PAGER: "less",
  HOME: "/Users/xixicat",
  CRASH_HOME: "/Users/xixicat/.gvm/crash/current",
  XPC_SERVICE_NAME: "0",
  VERTX_HOME: "/Users/xixicat/.gvm/vertx/current",
  GVM_BROADCAST_SERVICE: "http://cast.gvm.io",
  Apple_PubSub_Socket_Render: "/private/tmp/com.apple.launchd.y6fNwP8Sk6/Render",
  LSCOLORS: "Gxfxcxdxbxegedabagacad",
  ASCIIDOCTORJ_HOME: "/Users/xixicat/.gvm/asciidoctorj/current"
 },
 applicationConfig: [classpath: /application.properties]: {
  pool.acquireIncrement: "1",
  pool.minPoolSize: "5",
  pool.initialPoolSize: "1",
  database.username: "root",
  pool.maxIdleTime: "60",
  database.url: "jdbc:mysql://127.0.0.1:3307/video_uber?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull",
  spring.jackson.dateFormat: "yyyy-MM-dd'T'HH:mm:ss",
  database.slave.username: "root",
  spring.jackson.serialization.write - dates - as - timestamps: "false",
  pool.idleTimeout: "30000",
  database.slave.url: "jdbc:mysql://127.0.0.1:3307/demo?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull",
  server.port: "8080",
  database.slave.password: "******",
  database.password: "******",
  database.driverClassName: "com.mysql.jdbc.Driver",
  pool.maxPoolSize: "50",
  database.dataSourceClassName: "com.mysql.jdbc.jdbc2.optional.MysqlDataSource"
 }
}

/health

{
 status: "UP",
 diskSpace: {
  status: "UP",
  total: 249779191808,
  free: 193741590528,
  threshold: 10485760
 },
 db: {
  status: "UP",
  database: "MySQL",
  hello: 1
 }
}

/info

需要自己在application.properties里头添加信息,比如

info:
 contact:
  email: xixicat@gmail.com
  phone: 0755-82890987

然后请求就可以出来了

{
 "contact": {
   "phone": "0755-82890987",
   "email": "xixicat@gmail.com"
 }
}

/mappings

   {
    {
     [/metrics || /metrics.json], methods = [GET], produces = [application / json]
    }: {
     bean: "endpointHandlerMapping",
     method: "public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()"
    }, {
     [/beans || /beans.json], methods = [GET], produces = [application / json]
    }: {
     bean: "endpointHandlerMapping",
     method: "public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()"
    }, {
     [/health || /health.json], produces = [application / json]
    }: {
     bean: "endpointHandlerMapping",
     method: "public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint.invoke(java.security.Principal)"
    }, {
     [/info || /info.json], methods = [GET], produces = [application / json]
    }: {
     bean: "endpointHandlerMapping",
     method: "public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()"
    }, {
     [/trace || /trace.json], methods = [GET], produces = [application / json]
    }: {
     bean: "endpointHandlerMapping",
     method: "public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()"
    }, {
     [/autoconfig || /autoconfig.json], methods = [GET], produces = [application / json]
    }: {
     bean: "endpointHandlerMapping",
     method: "public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()"
    }
   }

/metrics

{
mem: 499404,
mem.free: 257591,
processors: 8,
instance.uptime: 4284997,
uptime: 4294909,
systemload.average: 1.84521484375,
heap.committed: 437248,
heap.init: 262144,
heap.used: 179656,
heap: 3728384,
nonheap.committed: 62848,
nonheap.init: 24000,
nonheap.used: 62156,
nonheap: 133120,
threads.peak: 18,
threads.daemon: 6,
threads.totalStarted: 176,
threads: 16,
classes: 10294,
classes.loaded: 10294,
classes.unloaded: 0,
gc.ps_scavenge.count: 11,
gc.ps_scavenge.time: 405,
gc.ps_marksweep.count: 0,
gc.ps_marksweep.time: 0,
datasource.primary.active: 0,
datasource.primary.usage: 0,
counter.status.200.autoconfig: 1,
counter.status.200.beans: 1,
counter.status.200.configprops: 1,
counter.status.200.dump: 1,
counter.status.200.env: 1,
counter.status.200.health: 1,
counter.status.200.info: 1,
counter.status.200.mappings: 1,
gauge.response.autoconfig: 81,
gauge.response.beans: 15,
gauge.response.configprops: 105,
gauge.response.dump: 76,
gauge.response.env: 4,
gauge.response.health: 43,
gauge.response.info: 1,
gauge.response.mappings: 4
}

/shutdown

要真正生效,得配置文件开启

endpoints.shutdown.enabled: true

/trace

记录最近100个请求的信息

[{
 "timestamp": 1452955704922,
 "info": {
  "method": "GET",
  "path": "/metrics",
  "headers": {
   "request": {
    "Accept - Encoding": "gzip, deflate, sdch",
     "Upgrade - Insecure - Requests": "1",
     "Accept - Language": "zh-CN,zh;q=0.8,en;q=0.6",
     "User - Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36",
     "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
     "Connection": "keep-alive",
     "Host": "localhost:8080"
   },
   "response": {
    "Content - Type": "application/json; charset=UTF-8",
     "X - Application - Context": "application:8080",
     "Date": "Sat, 16 Jan 2016 14:48:24 GMT",
     "status": "200"
   }
  }
 }
}, {
 "timestamp": 1452951489549,
 "info": {
  "method": "GET",
  "path": "/autoconfig",
  "headers": {
   "request": {
    "Accept - Encoding": "gzip, deflate, sdch",
     "Upgrade - Insecure - Requests": "1",
     "Accept - Language": "zh-CN,zh;q=0.8,en;q=0.6",
     "User - Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36",
     "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
     "Connection": "keep-alive",
     "Host": "localhost:8080"
   },
   "response": {
    "Content - Type": "application/json; charset=UTF-8",
     "X - Application - Context": "application:8080",
     "Date": "Sat, 16 Jan 2016 13:38:09 GMT",
     "status": "200"
   }
  }
 }
}]

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

(0)

相关推荐

  • Spring Boot 配置大全(小结)

    Spring Boot 允许通过外部配置让你在不同的环境使用同一应用程序的代码,简单说就是可以通过配置文件来注入属性或者修改默认的配置. SpringBoot的配置方式有很多,它们的优先级如下所示(优先级递减顺序): 1.命令行参数 2.来自java:comp/env的JNDI属性 3.Java系统属性(System.getProperties()) 4.操作系统环境变量 5.RandomValuePropertySource配置的random.*属性值 6.jar包外部的application

  • 超详细的Spring Boot入门笔记(总结)

    1. Spring Boot 入门 Spring Boot是Spring社区较新的一个项目.该项目的目的是帮助开发者更容易的创建基于Spring的应用程序和服务,让更多人的人更快的对Spring进行入门体验,让Java开发也能够实现Ruby on Rails那样的生产效率.为Spring生态系统提供了一种固定的.约定优于配置风格的框架. Spring Boot具有如下特性: 为基于Spring的开发提供更快的入门体验 开箱即用,没有代码生成,也无需XML配置.同时也可以修改默认值来满足特定的需求

  • SpringBoot快速构建应用程序方法介绍

    首先介绍一下SpringBoot在Coding上的使用场景.Coding中使用SpringBoot搭建的Email服务. 之所以选择SpringBoot,原因就是更加轻量级.在往常的Spring项目中,依赖的库太多,配置太繁杂,用在这只提供Email服务的程序上未免也小题大做了.而SpringBoot提供一些非功能性的常见的大型项目类特性(如内嵌服务器.安全.度量.健康检查.外部化配置)使得我们在部署上也更为方便,如可以直接地内嵌Tomcat/Jetty(不需要单独去部署war包) 1.Spri

  • 全面解析SpringBoot文件上传功能

    这些天忙着刷题,又怕遗忘了spring boot, 所以抽出一点时间折腾折腾,加深点印象. spring boot 的文件上传与 spring mvc 的文件上传基本一致,只需注意一些配置即可. 环境要求: Spring Boot v1.5.1.RELEASE + jdk1.7 + myeclipse 1).引入thymeleaf,支持页面跳转 <!-- 添加thymeleaf --> <dependency> <groupId>org.springframework.

  • spring boot+vue 的前后端分离与合并方案实例详解

    springboot和vue结合的方案网络上的主要有以下两种: 1. [不推荐]在html中直接使用script标签引入vue和一些常用的组件,这种方式和以前传统的开发是一样的,只是可以很爽的使用vue的双向数据绑定,这种方式只适合于普通的全栈开发. 2.[推荐]使用vue官方的脚手架创建单独的前端工程项目,做到和后端完全独立开发和部署,后端单独部署一个纯restful的服务,而前端直接采用nginx来部署,这种称为完全的前后端分离架构开发模式,但是在分离中有很多api权限的问题需要解决,包括部

  • Spring Boot与RabbitMQ结合实现延迟队列的示例

    背景 何为延迟队列? 顾名思义,延迟队列就是进入该队列的消息会被延迟消费的队列.而一般的队列,消息一旦入队了之后就会被消费者马上消费. 场景一:在订单系统中,一个用户下单之后通常有30分钟的时间进行支付,如果30分钟之内没有支付成功,那么这个订单将进行一场处理.这是就可以使用延时队列将订单信息发送到延时队列. 场景二:用户希望通过手机远程遥控家里的智能设备在指定的时间进行工作.这时候就可以将用户指令发送到延时队列,当指令设定的时间到了再将指令推送到只能设备. 延迟队列能做什么? 延迟队列多用于需

  • 详解如何将已有项目改造为Spring Boot项目

    快速创建一个springboot web工程 以IntelliJ IDEA为例: 1.首先创建一个项目,创建时选择Spring Initializr,然后Next,如下图: 2.填写项目信息,如下图: 3.勾选web 4.最后一步,填写工程名字点击finish 第一次创建时系统会去下载需要的依赖,耗时稍长,请耐心等待. 创建成功后,目录结构如下:项目的根目录下会有一个artifactId+Application命名规则的入口类,SpringbootLearningApplication Spri

  • spring-boot通过@Scheduled配置定时任务及定时任务@Scheduled注解的方法

    串行的定时任务 @Component public class ScheduledTimer { private Logger logger = Logger.getLogger(this.getClass()); /** * 定时任务,1分钟执行1次,更新潜在客户超时客户共享状态 */ @Scheduled(cron="0 0/1 8-20 * * ?") public void executeUpdateCuTask() { Thread current = Thread.curr

  • SpringBoot四大神器之Actuator的使用小结

    序 Spring Boot有四大神器,分别是auto-configuration.starters.cli.actuator,本文主要讲actuator.actuator是spring boot提供的对应用系统的自省和监控的集成功能,可以对应用系统进行配置查看.相关功能统计等. spring-boot-starter-actuator模块的实现对于实施微服务的中小团队来说,可以有效地减少监控系统在采集应用指标时的开发量.当然,它也并不是万能的,有时候我们也需要对其做一些简单的扩展来帮助我们实现自

  • SpringBoot四大神器之Auto onfiguration的使用

    目录 1. 通过启动类创建Spring Boot应用 2. @SpringBootApplication注解 2.1 @SpringBootConfiguration 2.2 @EnableAutoConfiguration 2.3 @ComponentScan 3.自定义自动配置 3.1 基于类的条件注解 3.2 基于Bean的条件注解 3.3 基于属性的条件注解 3.4 基于资源的条件注解 3.5 自定义条件 3.6 申请条件 4. 测试自动配置 5. 禁用自动配置类 6. 结论 Sprin

  • springboot 使用Spring Boot Actuator监控应用小结

    微服务的特点决定了功能模块的部署是分布式的,大部分功能模块都是运行在不同的机器上,彼此通过服务调用进行交互,前后台的业务流会经过很多个微服务的处理和传递,出现了异常如何快速定位是哪个环节出现了问题? 在这种框架下,微服务的监控显得尤为重要.本文主要结合Spring Boot Actuator,跟大家一起分享微服务Spring Boot Actuator的常见用法,方便我们在日常中对我们的微服务进行监控治理. Actuator监控 Spring Boot使用"习惯优于配置的理念",采用包

  • Spring Boot四大神器之CLI的具体使用

    目录 1. Spring Boot CLI简介: 2. 安装CLI: 3. 运行Groovy脚本 4. CLI运行原理说明:(CLI帮我们做了什么?) 1. Spring Boot CLI简介: 官网地址: https://docs.spring.io/spring-boot/docs/current/reference/html/cli.html#cli. 安装官网地址: https://docs.spring.io/spring-boot/docs/current/reference/htm

  • IDEA必备开发神器之EasyCode

    1.打开IntelliJ IDEA 新建一个maven工程 2.选择工程存放目录 3.下载安装EasyCode插件 file->settings->plugins 搜索Easy Code 搜索到后点击Install 我这里安装过了 安装完成会让你重启IDEA. 如何判断是否安装成功 file->settings->Other settings 看是否有Easy Code这个选项 4.引入Easy Code模板 (可以根据个人情况定制 也可以使用默认的) 5.创建数据库,数据表 6.

  • Spring Boot Actuator监控端点小结

    在Spring Boot的众多Starter POMs中有一个特殊的模块,它不同于其他模块那样大多用于开发业务功能或是连接一些其他外部资源.它完全是一个用于暴露自身信息的模块,所以很明显,它的主要作用是用于监控与管理,它就是:spring-boot-starter-actuator. spring-boot-starter-actuator模块的实现对于实施微服务的中小团队来说,可以有效地减少监控系统在采集应用指标时的开发量.当然,它也并不是万能的,有时候我们也需要对其做一些简单的扩展来帮助我们

  • SpringBoot实现文件上传下载功能小结

    最近做的一个项目涉及到文件上传与下载.前端上传采用百度webUploader插件.有关该插件的使用方法还在研究中,日后整理再记录.本文主要介绍SpringBoot后台对文件上传与下载的处理. 单文件上传 // 单文件上传 @RequestMapping(value = "/upload") @ResponseBody public String upload(@RequestParam("file") MultipartFile file) { try { if (

  • springboot实现拦截器之验证登录示例

    整理文档,搜刮出一个springboot实现拦截器之验证登录示例,稍微整理精简一下做下分享. 添加jar包,这个jar包不是必须的,只是在拦截器里用到了,如果不用的话,完全可以不引入 <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.5</version> </dep

  • SpringBoot 监控管理模块actuator没有权限的问题解决方法

    SpringBoot 1.5.9 版本加入actuator依赖后,访问/beans 等敏感的信息时候报错,如下 Tue Mar 07 21:18:57 GMT+08:00 2017 There was an unexpected error (type=Unauthorized, status=401). Full authentication is required to access this resource. 肯定是权限问题了.有两种方式: 1.关闭权限:application.prop

  • python三大神器之fabric使用教程

    fabric 是一个python包 是一个基于ssh的部署工具包 通常用来对网站 微服务等等的批量部署 例如 我有5台线上服务器 可以通过一台对着5台分发,实现自动部署的目的. 简单介绍下 fabric的常用命令 常用命令 lcd(dir): 进入本机某目录 local(cmd): 本机上执行命令 cd(dir): 进入服务器某目录 run(cmd):服务器上执行命令 Fabric Fabric是一个python的远程执行shell的库,同时它也是一个命令行工具.它提供了丰富的同 SSH 交互的

随机推荐