2016-09-29 5 views
0

봄에는 아래와 같이 나머지 웹 서비스를 디자인 할 수 있습니다. 우리가 이렇게하면스프링 부츠 액츄에이터 엔드 포인트 매핑 루트 클래스

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

는 @RestController & @RequestMapping은 내부적으로 요청 매핑 부분을 관리합니다. 그래서 url 즉 http://localhost:8080/hello을 누르면 printWelcome 메소드를 가리킬 것입니다.

나는 스프링 부트 액추에이터 소스 코드를 조사하고있었습니다. 우리가 우리의 응용 프로그램에서 스프링 부트 액추에이터를 사용한다면 우리는 헬스, 메트릭스, 정보와 같은 나머지 API들로 드러나는 몇몇 엔드 포인트를 제공 할 것입니다. 그래서 내 응용 프로그램에서 스프링 부트 액추에이터를 사용하고 있다면 "localhost : 8080/health"와 같은 url을 칠 때 응답을 얻습니다.

이제 제 질문은이 URL이 매핑되는 스프링 부트 액추에이터 소스 코드에 있습니다. 스프링 부트 액추에이터의 소스 코드를 디버깅했지만 엔드 포인트 매핑의 루트 클래스를 찾을 수 없습니다.

아무도 도와 줄 수 있습니까?

답변

1

here 그것이, AbstractEndpoint에서 당신이 HealthEndPoint가 표시되는 경우가 AbstractEndpoint를 확장하고 super("health", false);을 수행, 그것은 매핑 곳 ": 8080/건강 localhost"를 먹으 렴

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

을 말한다.

+0

Perfect. ! 고마워 .... – Harshil

1

모든 스프링 부트 액추에이터 종점은 종단점 ID가있는 구성자가 AbstractEndpoint (건강 종단점의 경우 : class HealthEndpoint extends AbstractEndpoint<Health>)를 확장합니다.

/** 
* 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; 

그렇지 않은 경우 엔드 포인트가 호출되어 (인터페이스 인 엔드 포인트에서) 호출 메소드가 있습니다.

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

마지막으로,이 엔드 포인트는 Bean로 클래스 EndpointAutoConfiguration으로 구성됩니다

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

설명이 게시물을 살펴보십시오 방법을 사용자 정의 엔드 포인트 :

+0

고마워 ... !!! – Harshil