Spring Boot 入门
来源:互联网 发布:绝对争锋网络剧在线 编辑:程序博客网 时间:2024/06/05 00:54
http://rensanning.iteye.com/blog/2363526#comments
2)设置端点访问
1-关闭验证
默认情况下很多端点是不允许访问的,会返回401:Unauthorized。
application.properties
引用
management.security.enabled=false
2-开启HTTP basic认证
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-security</artifactId>
- </dependency>
application.properties
引用
security.user.name=admin
security.user.password=123456
management.security.enabled=true
management.security.role=ADMIN
security.user.password=123456
management.security.enabled=true
management.security.role=ADMIN
访问URL http://localhost:8080/env 后,就看到需要输入用户名和密码了。
3-设置ContextPath
application.properties
引用
management.contextPath=/manage
那么URL就是:http://localhost:8080/manage/env
4-设置端口
application.properties
引用
management.port=8081
那么URL就是:http://localhost:8081/manage/env
(2)端点Endpoint
应用配置类
/autoconfig 获取应用的自动化配置报告
/beans 获取应用上下文中创建的所有Bean
/configprops 获取应用中配置的属性信息报告
/env 获取应用所有可用的环境属性报告
/mappings 获取应用所有Spring MVC的控制器映射关系报告
/info 获取应用自定义的信息
度量指标类
/metrics 返回应用的各类重要度量指标信息
/health 返回应用的各类健康指标信息
/dump 返回程序运行中的线程信息
/trace 返回基本的HTTP跟踪信息
操作控制类
/shutdown 用来远程关闭应用
(3)端点的开启或禁用
application.properties
引用
endpoints.configprops.enabled=false
endpoints.shutdown.enabled=true
endpoints.shutdown.enabled=true
(4)自定义端点
1-自定义已有端点,比如 /health 端点
- @Component
- public class CustomHealth implements HealthIndicator {
- public Health health() {
- return Health.up().build();
- }
- }
访问URL:http://localhost:8081/manage/health
2-创建新的端点
- @Component
- public class CustomEndpoint implements Endpoint<List<String>> {
- public String getId() {
- return "myep";
- }
- public boolean isEnabled() {
- return true;
- }
- public boolean isSensitive() {
- return true;
- }
- public List<String> invoke() {
- List<String> messages = new ArrayList<String>();
- messages.add("This is message 1");
- messages.add("This is message 2");
- return messages;
- }
- }
访问URL:http://localhost:8081/manage/myep
3-列举所有端点
- @Component
- public class ListEndpoints extends AbstractEndpoint<List<Endpoint>> {
- private List<Endpoint> endpoints;
- @Autowired
- public ListEndpoints(List<Endpoint> endpoints) {
- super("allep");
- this.endpoints = endpoints;
- }
- public List<Endpoint> invoke() {
- return this.endpoints;
- }
- }
访问URL:http://localhost:8081/manage/allep
(5)自定义端点metrics
Spring Boot允许开发人员以编码的方式提供更丰富指标信息,通过/metrics端点来访问。counter是以Number类型来展现的指标;gauge是衡量双精度计算的指标。任何位置都可以注入CounterService或GaugeService。
- counterService.increment("metricName");
- counterService.decrement("metricName");
- counterService.reset("metricName");
- gaugeService.submit("metricName", 2.5);
参考:
http://www.baeldung.com/spring-boot-actuators
http://blog.didispace.com/spring-boot-actuator-1/
阅读全文
0 0
- 【Spring Boot】Spring Boot 入门
- Spring Boot 快速入门
- spring boot 入门
- Spring Boot 入门
- Spring Boot 入门
- spring boot简易入门
- Spring boot入门
- Spring Boot 快速入门
- Spring boot快速入门
- Spring boot 入门 实例
- Spring Boot 快速入门
- spring boot入门(一)
- spring boot入门例
- Spring Boot入门例子
- spring boot 入门
- Spring Boot入门
- Spring Boot 快速入门
- Spring Boot 入门笔记
- Android编译X264、fdkaac和FFmpeg
- 289. Game of Life
- hdu 1231 最大连续子序列
- hdu 1159 Common Subsequence
- 实现函数method(x,y),求x的y次方的最后三位数,x,y都为小于100的正整数。
- Spring Boot 入门
- 486. Predict the Winner
- 转发 和 重定向
- LCS模板,求长度,并记录子串
- 背包(采药)
- CSS 继承Body元素样式
- hdu 1175 连连看
- hdu 1180 诡异的楼梯
- hdu 1195 Open the Lock