0 课程地址
http://coding.imooc.com/lesson/380.html#mid=28363
1 浓缩精华
1.1 浓缩精华
4.1,4.2
2 个人关注
3 课程内容
4 代码演练
4.1 自定义端点
配置类:
package com.imooc.springboot.application.config; import com.imooc.springboot.application.endpoint.DateTimeEndPoint; import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** * EndPointConfig * * @author 魏豆豆 * @date 2021/4/5 */ @Configuration public class EndPointConfig { //自己,大概是读取datetimeEndPoint的,设置端点 //记一下 @Bean @ConditionalOnMissingBean//当该bean缺少的时候注入bean @ConditionalOnEnabledEndpoint//当监控端点开启的时候(application.yml打开监控端点)才会注入应用程序 public DateTimeEndPoint dateTimeEndPoint(){ return new DateTimeEndPoint(); } }
自定义端点类
package com.imooc.springboot.application.endpoint; import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.Map; /** * DateTimeEndPoint * * @author 魏豆豆 * @date 2021/4/5 */ @Endpoint(id="datetime") public class DateTimeEndPoint{ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); /** * 读取端点注解 * @return */ @ReadOperation//显示监控指标 public Map<String,Object> readPoint(){ Map<String,Object> map = new HashMap(); map.put("name","小魏"); map.put("age","18"); map.put("birthday",simpleDateFormat.format(new Date())); return map; } }
打印日志:
4.2 自定义端点(写入)
配置类(同上)
自定义端点类:
package com.imooc.springboot.application.endpoint; import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; import org.springframework.boot.actuate.endpoint.annotation.WriteOperation; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.Map; /** * DateTimeEndPoint * * @author 魏豆豆 * @date 2021/4/5 */ @Endpoint(id="datetime") public class DateTimeEndPoint{ private String forMat = "yyyy-MM-dd"; /** * 读取端点注解 * @return */ @ReadOperation//显示监控指标 public Map<String,Object> readPoint(){ Map<String,Object> map = new HashMap(); map.put("name","小魏"); map.put("age","18"); map.put("birthday",new SimpleDateFormat(forMat).format(new Date())); return map; } //记一下 @WriteOperation public void writePoint(String forMat){ this.forMat = forMat; } }
post方式写入日期格式
get读取