Removed all Sysout's instead using SLF4J logger

This commit is contained in:
K. Naveen Kumar
2021-05-20 21:21:04 +05:30
parent ab79a6be97
commit 46fe09352e
4 changed files with 16 additions and 6 deletions

View File

@@ -1,5 +1,7 @@
package io.reflectoring.springboot.testconfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -9,6 +11,7 @@ import org.springframework.web.reactive.function.client.WebClient;
@Configuration
public class WebClientConfiguration {
private static final Logger LOGGER = LoggerFactory.getLogger(WebClientConfiguration.class);
@Bean
public WebClient getWebClient(final WebClient.Builder builder,
@Value("${data.service.endpoint:https://google.com}") final String url) {
@@ -16,7 +19,7 @@ public class WebClientConfiguration {
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
// more configurations and customizations
.build();
System.out.println("WebClient Instance Created During Testing: " + webClient.toString());
LOGGER.info("WebClient Bean Instance: {}", webClient);
return webClient;
}
}

View File

@@ -1,13 +1,16 @@
package io.reflectoring.springboot.testconfiguration.service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;
@Service
public class DataService {
private static final Logger LOGGER = LoggerFactory.getLogger(DataService.class);
private final WebClient webClient;
public DataService(final WebClient webClient) {
this.webClient = webClient;
System.out.println("WebClient instance " + this.webClient.toString());
LOGGER.info("WebClient instance {}", this.webClient);
}
}

View File

@@ -2,6 +2,8 @@ package io.reflectoring.springboot.testconfiguration;
import io.reflectoring.springboot.testconfiguration.service.DataService;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
@@ -21,13 +23,13 @@ public class UsingStaticInnerTestConfiguration {
@TestConfiguration
public static class WebClientTestConfiguration {
private static final Logger LOGGER = LoggerFactory.getLogger(WebClientTestConfiguration.class);
@Bean
public WebClient getWebClient(final WebClient.Builder builder) {
WebClient webClient = builder
.baseUrl("http://localhost")
.build();
System.out.println("WebClient Instance Created During Testing, using static inner class: "
+ webClient.toString());
LOGGER.info("WebClient Instance Created During Testing, using static inner class: {}", webClient);
return webClient;
}
}

View File

@@ -1,18 +1,20 @@
package io.reflectoring.springboot.testconfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.web.reactive.function.client.WebClient;
@TestConfiguration
public class WebClientTestConfiguration {
private static final Logger LOGGER = LoggerFactory.getLogger(UsingStaticInnerTestConfiguration.WebClientTestConfiguration.class);
@Bean
public WebClient getWebClient(final WebClient.Builder builder) {
WebClient webClient = builder
.baseUrl("http://localhost")
.build();
System.out.println("WebClient Instance Created During Testing: " + webClient.toString());
LOGGER.info("WebClient Instance Created During Testing: {}", webClient);
return webClient;
}
}