作者 Michael Redlich ,译者 张卫滨
即将发布的 Spring Boot 2.0.0 M4 将会增强 actuator 端点 基础设施的特性。最重要的变更包括:
Spring Boot 的 actuator 端点 允许监控 Web 应用,并且可以与 Web 应用进行交互。在此之前,这些端点只支持 Spring MVC,如果创建自定义端点的话,需要大量额外的编码和配置。
内置的端点,比如    /beans
、    /health
等等,现在都映射到了    /application
根上下文下。比如,之前 Spring Boot 版本中的    /beans
现在需要通过    /application/beans
进行访问。  
新的    @Enpoint
注解简化了创建用户自定义端点的过程。如下的样例创建了名为    person
的端点。(完整的示例应用可以在    GitHub
上查看。)  
@Endpoint(id = "person")
@Component
public class PersonEndpoint {
    private final Map<String, Person> people = new HashMap<>();
    PersonEndpoint() {
        this.people.put("mike", new Person("Michael Redlich"));
        this.people.put("rowena", new Person("Rowena Redlich"));
        this.people.put("barry", new Person("Barry Burd"));
    }
    @ReadOperation
    public List<Person> getAll() {
        return new ArrayList<>(this.people.values());
    }
    @ReadOperation
    public Person getPerson(@Selector String person) {
        return this.people.get(person);
    }
    @WriteOperation
    public void updatePerson(@Selector String name, String person) {
        this.people.put(name, new Person(person));
    }
    public static class Person {
        private String name;
        Person(String name) {
            this.name = name;
        }
        public String getName() {
            return this.name;
        }
        public void setName(String name) {
            this.name = name;
        }
    }
}
  
这个端点借助    @ReadOperation
和    @WriteOperation
注解暴露了三个方法。这个端点的定义不再需要额外的代码,它可以通过    /application/person
和    /application/person/{name}
进行访问。另外,这个端点同时还会自动部署为 JMX    MBean
,可以通过像 JConsole 这样的 JMX 客户端来访问。  
Spring Boot 2.0 采用一种稍微不同的方式来确保 Web 端点默认的    安全性
。Web 端点默认是禁用的,    management.security.enabled
属性已经被移除掉了。单个端点可以通过    application.properties
文件中的配置来启用。比如:  
endpoints.info.enabled=true endpoints.beans.enabled=true
但是,我们还可以把    endpoints.default.web.enabled
属性设置为    true
,从而将 actuator 和用户自定义的所有端点暴露出去。  
Stéphane Nicoll 是 Pivotal 的首席软件工程师,关于 actuator 的端点事宜,InfoQ 与他进行了交流。
Stéphane Nicoll:同时支持基于 servlet 的传统环境以及基于 reactive 理念的 Web App 是一个很大的挑战,尤其是在处理可扩展性特性方面更是如此。
Nicoll:在框架团队中,“spring-webmvc”和“spring-webflux”共享了很多来自“spring-web”的特性,其中我们可以看到很多创造性的设计。构建抽象是非常困难的,我非常开心我们在另外一个层级上完成了相同的事情。
Nicoll:Spring Boot 2.0 主要关注于搭建坚实的基础和良好的共识:我们相信这个新的端点基础设施方向是正确的,它所针对的是生产环境的特性,我们期待来自社区的反馈。
Nicoll:事情尚不确定(双关语,这里原文使用的是 flux,可能同时指不确定性和对 WebFlux 的支持),但是我们 目前的计划 是在年底释放 Spring Boot 2.0 GA。
查看英文原文: Spring Boot 2.0 Will Feature Improved Actuator Endpoints
转自 http://www.infoq.com/cn/news/2017/09/spring-boot-2-actuator-endpoints