2016-10-07 2 views
1

내 수업에 주입 된 OkHttpClient 개체를 사용하고 있습니다. 나는 다음과 같이 내 클라이언트 객체에 대한 몇 가지 인터셉터를 설정하는 방법 주입을 사용하고 있습니다 : 나는 onPostInject 방법에 중단 점을 넣을 경우OkHttpClient 인터셉터가 설정되지 않음

@Inject 
private OkHttpClient httpClient; 

@Inject 
void onPostInject() { 
    httpClient 
     .newBuilder() 
     .addInterceptor(loggingInterceptor) 
     .addInterceptor(httpClientInterceptor); 
} 

를 이제 마지막 문에 도달, 나는 httpClient 객체 내 interceptors 모음의 크기가 참조 0. 같은 이유로 My Integration 테스트도 실패합니다.

+0

당신은 당신이 만들고'interceptor'을 초기화하는 방법 약간의 코드를 추가 할 수 있습니까? – Pr38y

답변

0

나는 httpClient 필드에서 주입을 제거하고 일을 얻기 위해 조금 다른 빌드를 사용했다 :

private OkHttpClient httpClient; 

@Inject 
void onPostInject() { 
    httpClient = 
     new OkHttpClient.Builder() 
     .addInterceptor(loggingInterceptor) 
     .addInterceptor(httpClientInterceptor) 
     .build(); 
}