2016-09-29 34 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