주 스프링 부트 프로젝트와 별도의 jar 파일로 필터를 만들려고합니다. 그 중 하나는 액츄에이터의 트레이스 필터 (/trace 호출시 실행되는 필터)이며, /trace에 대한 호출을 추적하지 않도록 구성합니다. 프로젝트 내부에서 필터를 정의하면 완벽하게 작동하며 /trace에 대한 호출을 추적하지 않습니다.액추에이터 (Springboot)에서 TraceFilter 구성이 작동하지 않습니다.
그러나 클래스를 다른 라이브러리로 추출하여 주 프로젝트에서 참조하면 해당 호출을 추적합니다. 모든 참조가 올바른지 확인하고 필터가 실행 중입니다. 그러나, 나는 종속성을 초기화 할 때 내 필터와 WebRequestTraceFilter (내 필터의 클래스가 상속 됨)가 모두 인스턴스화되는 것으로 의심된다. 이 필터 클래스입니다 :
package common.api.filters.trace;
import org.springframework.boot.actuate.trace.TraceProperties;
import org.springframework.boot.actuate.trace.TraceRepository;
import org.springframework.boot.actuate.trace.WebRequestTraceFilter;
import org.springframework.stereotype.Component;
import org.springframework.util.AntPathMatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
/**
* Class to exclude some some endpoints to be traced such as /admin/**, * /trace and
* endpoints provide static files like /css/** and /js/**.
*/
@Component
public class RequestTraceFilter extends WebRequestTraceFilter {
private static final String[] excludedEndpoints = new String[]{"/css/**", "/js/**", "/trace"};
public RequestTraceFilter(TraceRepository repository, TraceProperties properties) {
super(repository, properties);
}
/*
The default implementation was always returning false.
With this implementation, it returns true for the endpoints we don’t want to trace.
*/
@Override
protected boolean shouldNotFilter(final HttpServletRequest request) throws ServletException {
return Arrays
.stream(excludedEndpoints)
.anyMatch(e -> new AntPathMatcher().match(e, request.getServletPath()));
}
}
또한 태그 @Component를 제거하고 필터를 @Configuration 태그 클래스에서이 방법으로 초기화 시도
:
@Bean
public FilterRegistrationBean createTraceFilter(){
FilterRegistrationBean frb = new FilterRegistrationBean();
frb.setFilter(new RequestTraceFilter(new InMemoryTraceRepository(), new TraceProperties()));
return frb;
}
을하지만 결과는 동일 : 필터가 실행 중이지만/trace에 대한 호출이 추적 중입니다.
기본 프로젝트의 필터를 추적 할 때 실행되는 유일한 필터로 초기화하려면 어떻게해야합니까?