Skip to content

Instantly share code, notes, and snippets.

@zeroows
Created April 8, 2017 14:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zeroows/8e8cb53e1e8f26edde09be8ed365e357 to your computer and use it in GitHub Desktop.
Save zeroows/8e8cb53e1e8f26edde09be8ed365e357 to your computer and use it in GitHub Desktop.
Retrofit Configuration for Spring Boot
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.aalkhodiry.notifications.utils.LoggingInterceptor;
import okhttp3.OkHttpClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
/**
* Created by zeroows on 02/10/16.
*/
@Configuration
public class RetrofitConfiguration {
@Autowired
private LoggingInterceptor loggingInterceptor;
@Value("${oneSignal.url}")
private String url;
@Bean
@Autowired
public Retrofit retrofit(OkHttpClient client, Gson gson) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(url)
.client(client)
.addConverterFactory(GsonConverterFactory.create(gson))
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.build();
return retrofit;
}
@Bean
public OkHttpClient client() {
final OkHttpClient.Builder okHttpClientBuilder = new OkHttpClient.Builder();
final OkHttpClient builtClient = okHttpClientBuilder.addInterceptor(loggingInterceptor).build();
return builtClient;
}
@Bean
public Gson gson() {
return new GsonBuilder().setLenient().create();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment