From 29a5e2f5e1e80776bb0da0f20b4d8c8189a9ccc5 Mon Sep 17 00:00:00 2001 From: Naeem Ullah Date: Mon, 5 Jan 2026 14:47:18 +0500 Subject: [PATCH] Refactor AuthService to use default RestTemplate and ObjectMapper Replaces constructor-based dependency injection with direct instantiation of RestTemplate and ObjectMapper in AuthService. Simplifies the class by removing the constructor and initializing dependencies inline. --- .../aconnect/client/service/AuthService.java | 9 ++------- .../configuration/config/RestTemplateConfig.java | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 aconnect/src/main/java/com/mfsys/aconnect/configuration/config/RestTemplateConfig.java diff --git a/aconnect/src/main/java/com/mfsys/aconnect/client/service/AuthService.java b/aconnect/src/main/java/com/mfsys/aconnect/client/service/AuthService.java index 6f33d19..9daedc7 100644 --- a/aconnect/src/main/java/com/mfsys/aconnect/client/service/AuthService.java +++ b/aconnect/src/main/java/com/mfsys/aconnect/client/service/AuthService.java @@ -19,13 +19,8 @@ public class AuthService { @Value("${app.security.uri}") private String securityURI; - private final RestTemplate restTemplate; - private final ObjectMapper objectMapper; - - public AuthService(RestTemplate restTemplate, ObjectMapper objectMapper) { - this.restTemplate = restTemplate; - this.objectMapper = objectMapper; - } + private final RestTemplate restTemplate = new RestTemplate(); + private final ObjectMapper objectMapper = new ObjectMapper(); public Map authenticate(Map payload) { diff --git a/aconnect/src/main/java/com/mfsys/aconnect/configuration/config/RestTemplateConfig.java b/aconnect/src/main/java/com/mfsys/aconnect/configuration/config/RestTemplateConfig.java new file mode 100644 index 0000000..40f281a --- /dev/null +++ b/aconnect/src/main/java/com/mfsys/aconnect/configuration/config/RestTemplateConfig.java @@ -0,0 +1,15 @@ +package com.mfsys.aconnect.configuration.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.web.client.RestTemplate; + +@Configuration +public class RestTemplateConfig { + + @Bean + public RestTemplate restTemplate() { + return new RestTemplate(new HttpComponentsClientHttpRequestFactory()); + } +}