Skip to content

Instantly share code, notes, and snippets.

@truongquoc
Last active October 17, 2023 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save truongquoc/7bd77ab86de140182a94bba9f8ca3651 to your computer and use it in GitHub Desktop.
Save truongquoc/7bd77ab86de140182a94bba9f8ca3651 to your computer and use it in GitHub Desktop.
CustomBeanConfiguration
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
@Service
public class AuthService {
private final RestTemplate customRestTemplate;
@Autowired
public AuthService(RestTemplate customRestTemplate) {
this.customRestTemplate = customRestTemplate;
}
// Use the customized RestTemplate in your service
}
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
@Configuration
public class CustomBeanConfiguration {
@Bean
public RestTemplate customRestTemplate() {
RestTemplate restTemplate = new RestTemplate();
// Customize the RestTemplate with connection timeout
restTemplate.setRequestFactory(new SimpleClientHttpRequestFactory());
((SimpleClientHttpRequestFactory) restTemplate.getRequestFactory()).setConnectTimeout(connectionTimeout);
return restTemplate;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment