2016-09-29 25 views
0

在春天我们可以设计如下的其他Web服务。弹簧启动执行器端点映射根类

@RestController 
public class HelloController { 
    @RequestMapping(value = "/hello", method = RequestMethod.GET) 
    public String printWelcome(ModelMap model) { 
     model.addAttribute("message", "Hello"); 
     return "hello"; 
    } 
} 

当我们这样做,@RestController & @RequestMapping将在内部管理请求映射的一部分。所以当我点击网址即http://localhost:8080/hello时,它会指向printWelcome方法。

我正在考虑春季启动执行器源代码。如果我们将在我们的应用中使用弹簧启动执行器,它将为我们提供一些终端,这些终端暴露为健康,度量,信息等其他API。因此,在我的应用程序中,如果我使用弹簧启动执行器,当我点击“localhost:8080/health”这个网址时,我会得到回复。

所以,现在我的问题是在这个URL映射的春季启动执行器源代码。我调试了spring启动驱动程序的源代码,但无法找到端点映射的根类。

任何人都可以请帮忙吗?

回答

1

here是,在AbstractEndpoint它说

/** 
    * Endpoint identifier. With HTTP monitoring the identifier of the endpoint is mapped 
    * to a URL (e.g. 'foo' is mapped to '/foo'). 
    */ 

如果你看到HealthEndPoint它延伸AbstractEndpoint和做了super("health", false);,多数民众赞成在它映射为 “localhost:8080 /健康”。

+0

完美。 !谢谢.... – Harshil

1

所有弹簧启动执行器端点扩展了AbstractEndpoint(在Health端点情况下,例如:class HealthEndpoint extends AbstractEndpoint<Health>),其中construcor具有Endpoint的id。

/** 
* Endpoint identifier. With HTTP monitoring the identifier of the endpoint is mapped 
* to a URL (e.g. 'foo' is mapped to '/foo'). 
*/ 
private String id; 

否则,它有一个invoke方法(从接口端点)通过它调用端点。

/** 
* Called to invoke the endpoint. 
* @return the results of the invocation 
*/ 
T invoke(); 

最后,终点在类EndpointAutoConfiguration配置为Bean

@Bean 
@ConditionalOnMissingBean 
public HealthEndpoint healthEndpoint() { 
    return new HealthEndpoint(this.healthAggregator, this.healthIndicators); 
} 

看看这个帖子里介绍如何自定义您的端点:

+0

谢谢男人...... !!! – Harshil