Last active
October 17, 2023 08:41
-
-
Save truongquoc/7bd77ab86de140182a94bba9f8ca3651 to your computer and use it in GitHub Desktop.
CustomBeanConfiguration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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