From a851fe03d576b3ab50de480de4d15a6c170fee5f Mon Sep 17 00:00:00 2001 From: bsmahi Date: Sat, 20 Apr 2024 21:07:44 +0530 Subject: [PATCH] Upgraded to Spring Boot 3.2.x and JDK 21 --- .../currency-exchange-microservice/.gitignore | 1 + .../currency-exchange-microservice/Dockerfile | 2 +- .../currency-exchange-microservice/pom.xml | 64 +++++++++++++------ .../resource/CurrencyExchangeController.java | 2 +- .../resource/ExchangeValue.java | 6 +- .../src/main/resources/application.properties | 1 + ...rrencyExchangeServiceApplicationTests.java | 8 +-- .../CucumberSpringContextConfiguration.java | 5 +- .../cucumber/CurrencyExchangeSteps.java | 11 ++-- .../cucumber/HelloWorldSteps.java | 14 ++-- .../RunCucumberIntegrationTestCase.java | 8 +-- .../CurrencyExchangeControllerTest.java | 6 +- kubernetes/01-hello-world-rest-api/.gitignore | 1 + kubernetes/01-hello-world-rest-api/Dockerfile | 2 +- kubernetes/01-hello-world-rest-api/pom.xml | 5 +- .../RestfulWebServicesApplicationTests.java | 8 +-- .../hello-world/hello-world-java/.gitignore | 1 + .../hello-world/hello-world-java/Dockerfile | 4 +- projects/hello-world/hello-world-java/pom.xml | 4 +- .../RestfulWebServicesApplicationTests.java | 8 +-- .../Dockerfile | 4 +- .../pom.xml | 33 +++++----- .../resource/CurrencyExchangeController.java | 2 +- .../resource/ExchangeValue.java | 6 +- .../security/SecurityConfiguration.java | 20 +++--- .../src/main/resources/application.properties | 2 + ...rrencyExchangeServiceApplicationTests.java | 5 +- .../.gitignore | 1 + .../Dockerfile | 4 +- .../pom.xml | 31 ++++----- .../security/SecurityConfiguration.java | 18 +++--- .../src/main/resources/application.properties | 2 + ...encyConversionServiceApplicationTests.java | 8 +-- 33 files changed, 161 insertions(+), 136 deletions(-) create mode 100644 jenkins/currency-exchange-microservice/.gitignore create mode 100644 kubernetes/01-hello-world-rest-api/.gitignore create mode 100644 projects/hello-world/hello-world-java/.gitignore create mode 100644 projects/microservices/02-currency-conversion-microservice-basic/.gitignore diff --git a/jenkins/currency-exchange-microservice/.gitignore b/jenkins/currency-exchange-microservice/.gitignore new file mode 100644 index 00000000..723ef36f --- /dev/null +++ b/jenkins/currency-exchange-microservice/.gitignore @@ -0,0 +1 @@ +.idea \ No newline at end of file diff --git a/jenkins/currency-exchange-microservice/Dockerfile b/jenkins/currency-exchange-microservice/Dockerfile index df6987de..80343472 100755 --- a/jenkins/currency-exchange-microservice/Dockerfile +++ b/jenkins/currency-exchange-microservice/Dockerfile @@ -1,4 +1,4 @@ -FROM openjdk:8-jdk-alpine +FROM openjdk:21-jdk-slim VOLUME /tmp EXPOSE 8000 ADD target/*.jar app.jar diff --git a/jenkins/currency-exchange-microservice/pom.xml b/jenkins/currency-exchange-microservice/pom.xml index ca9a6666..5d27708f 100755 --- a/jenkins/currency-exchange-microservice/pom.xml +++ b/jenkins/currency-exchange-microservice/pom.xml @@ -15,19 +15,20 @@ org.springframework.boot spring-boot-starter-parent - 2.1.1.RELEASE + 3.2.5 + null UTF-8 UTF-8 - 1.8 + 21 3.1.1 - Greenwich.SR3 + 2023.0.1 - 2.22.1 - 2.22.1 + 3.1.2 + 3.1.2 0.8.3 ${settings.localRepository}/org/jacoco/org.jacoco.agent/${jacoco.version}/org.jacoco.agent-${jacoco.version}-runtime.jar @@ -64,22 +65,17 @@ - javax.xml.bind - jaxb-api - - - com.sun.xml.bind - jaxb-impl - 2.3.1 + jakarta.xml.bind + jakarta.xml.bind-api org.glassfish.jaxb jaxb-runtime - javax.activation - activation - 1.1.1 + jakarta.activation + jakarta.activation-api + 1.2.2 @@ -91,25 +87,36 @@ io.rest-assured rest-assured-all - 4.0.0 test io.cucumber cucumber-spring - 4.2.0 + 7.17.0 test io.cucumber cucumber-java - 2.3.1 + 7.17.0 test io.cucumber cucumber-junit - 2.3.1 + 7.17.0 + test + + + junit + junit + + + + + io.cucumber + cucumber-junit-platform-engine + 7.17.0 test @@ -119,6 +126,24 @@ runtime test + + org.junit.jupiter + junit-jupiter + test + + + + org.junit.platform + junit-platform-launcher + 1.10.2 + test + + + org.junit.jupiter + junit-jupiter-engine + 5.10.2 + test + org.sonarsource.java sonar-jacoco-listeners @@ -133,7 +158,6 @@ io.rest-assured rest-assured - 4.1.2 test diff --git a/jenkins/currency-exchange-microservice/src/main/java/com/in28minutes/microservices/currencyexchangeservice/resource/CurrencyExchangeController.java b/jenkins/currency-exchange-microservice/src/main/java/com/in28minutes/microservices/currencyexchangeservice/resource/CurrencyExchangeController.java index 5b305e3c..b0210003 100755 --- a/jenkins/currency-exchange-microservice/src/main/java/com/in28minutes/microservices/currencyexchangeservice/resource/CurrencyExchangeController.java +++ b/jenkins/currency-exchange-microservice/src/main/java/com/in28minutes/microservices/currencyexchangeservice/resource/CurrencyExchangeController.java @@ -50,7 +50,7 @@ public ExchangeValue retrieveExchangeValue(@PathVariable String from, @PathVaria private void printAllHeaders(Map headers) { headers.forEach((key, value) -> { - LOGGER.info(String.format("Header '%s' = %s", key, value)); + LOGGER.info("Header '%s' = %s".formatted(key, value)); }); } } diff --git a/jenkins/currency-exchange-microservice/src/main/java/com/in28minutes/microservices/currencyexchangeservice/resource/ExchangeValue.java b/jenkins/currency-exchange-microservice/src/main/java/com/in28minutes/microservices/currencyexchangeservice/resource/ExchangeValue.java index ab76b49a..402e6563 100755 --- a/jenkins/currency-exchange-microservice/src/main/java/com/in28minutes/microservices/currencyexchangeservice/resource/ExchangeValue.java +++ b/jenkins/currency-exchange-microservice/src/main/java/com/in28minutes/microservices/currencyexchangeservice/resource/ExchangeValue.java @@ -2,9 +2,9 @@ import java.math.BigDecimal; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; @Entity public class ExchangeValue { diff --git a/jenkins/currency-exchange-microservice/src/main/resources/application.properties b/jenkins/currency-exchange-microservice/src/main/resources/application.properties index cf861c50..c2b8d702 100755 --- a/jenkins/currency-exchange-microservice/src/main/resources/application.properties +++ b/jenkins/currency-exchange-microservice/src/main/resources/application.properties @@ -4,6 +4,7 @@ server.port=8000 spring.jpa.show-sql=true spring.h2.console.enabled=true spring.h2.console.settings.web-allow-others=true +spring.jpa.defer-datasource-initialization=true #logging.level.org.springframework=debug management.endpoints.web.base-path=/manage diff --git a/jenkins/currency-exchange-microservice/src/test/java/com/in28minutes/microservices/currencyexchangeservice/CurrencyExchangeServiceApplicationTests.java b/jenkins/currency-exchange-microservice/src/test/java/com/in28minutes/microservices/currencyexchangeservice/CurrencyExchangeServiceApplicationTests.java index f4f82fe1..af32936c 100755 --- a/jenkins/currency-exchange-microservice/src/test/java/com/in28minutes/microservices/currencyexchangeservice/CurrencyExchangeServiceApplicationTests.java +++ b/jenkins/currency-exchange-microservice/src/test/java/com/in28minutes/microservices/currencyexchangeservice/CurrencyExchangeServiceApplicationTests.java @@ -1,12 +1,12 @@ package com.in28minutes.microservices.currencyexchangeservice; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; -@RunWith(SpringRunner.class) @SpringBootTest +@ExtendWith(MockitoExtension.class) public class CurrencyExchangeServiceApplicationTests { @Test diff --git a/jenkins/currency-exchange-microservice/src/test/java/com/in28minutes/microservices/currencyexchangeservice/cucumber/CucumberSpringContextConfiguration.java b/jenkins/currency-exchange-microservice/src/test/java/com/in28minutes/microservices/currencyexchangeservice/cucumber/CucumberSpringContextConfiguration.java index 5e2ca201..481e4045 100755 --- a/jenkins/currency-exchange-microservice/src/test/java/com/in28minutes/microservices/currencyexchangeservice/cucumber/CucumberSpringContextConfiguration.java +++ b/jenkins/currency-exchange-microservice/src/test/java/com/in28minutes/microservices/currencyexchangeservice/cucumber/CucumberSpringContextConfiguration.java @@ -1,5 +1,6 @@ package com.in28minutes.microservices.currencyexchangeservice.cucumber; +import org.junit.jupiter.api.BeforeEach; import org.springframework.boot.test.context.SpringBootContextLoader; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; @@ -7,13 +8,11 @@ import com.in28minutes.microservices.currencyexchangeservice.CurrencyExchangeServiceApplicationH2; -import cucumber.api.java.Before; - @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) @ContextConfiguration(classes = CurrencyExchangeServiceApplicationH2.class, loader = SpringBootContextLoader.class) public class CucumberSpringContextConfiguration { - @Before + @BeforeEach public void setUp() { } } \ No newline at end of file diff --git a/jenkins/currency-exchange-microservice/src/test/java/com/in28minutes/microservices/currencyexchangeservice/cucumber/CurrencyExchangeSteps.java b/jenkins/currency-exchange-microservice/src/test/java/com/in28minutes/microservices/currencyexchangeservice/cucumber/CurrencyExchangeSteps.java index 2e6787c2..32b71dcc 100755 --- a/jenkins/currency-exchange-microservice/src/test/java/com/in28minutes/microservices/currencyexchangeservice/cucumber/CurrencyExchangeSteps.java +++ b/jenkins/currency-exchange-microservice/src/test/java/com/in28minutes/microservices/currencyexchangeservice/cucumber/CurrencyExchangeSteps.java @@ -1,9 +1,9 @@ package com.in28minutes.microservices.currencyexchangeservice.cucumber; -import cucumber.api.java.en.Given; -import cucumber.api.java.en.Then; -import cucumber.api.java.en.When; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; import io.restassured.RestAssured; import io.restassured.builder.RequestSpecBuilder; import io.restassured.http.ContentType; @@ -11,8 +11,7 @@ import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; import io.restassured.response.ValidatableResponse; - -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; import static io.restassured.RestAssured.when; @@ -42,7 +41,7 @@ public void the_system_is_asked_to_provide_the_conversion_rate() throws Exceptio @Then("^It should output (.*)$") public void thenCheckOutput(float response) { - Assert.assertEquals(output, response,0.5); + Assertions.assertEquals(output, response,0.5); } diff --git a/jenkins/currency-exchange-microservice/src/test/java/com/in28minutes/microservices/currencyexchangeservice/cucumber/HelloWorldSteps.java b/jenkins/currency-exchange-microservice/src/test/java/com/in28minutes/microservices/currencyexchangeservice/cucumber/HelloWorldSteps.java index f5035da0..5d4ea919 100755 --- a/jenkins/currency-exchange-microservice/src/test/java/com/in28minutes/microservices/currencyexchangeservice/cucumber/HelloWorldSteps.java +++ b/jenkins/currency-exchange-microservice/src/test/java/com/in28minutes/microservices/currencyexchangeservice/cucumber/HelloWorldSteps.java @@ -1,9 +1,10 @@ package com.in28minutes.microservices.currencyexchangeservice.cucumber; -import cucumber.api.java.en.Given; -import cucumber.api.java.en.Then; -import cucumber.api.java.en.When; -import org.junit.Assert; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; + +import org.junit.jupiter.api.Assertions; import com.in28minutes.microservices.currencyexchangeservice.HelloWorld; @@ -20,16 +21,17 @@ public class HelloWorldSteps { public void givenInput(String name) { this.name = name; } + @When("^sayHello method of HelloWorld.java is called$") public void whenBusinessLogicCalled() { output = helloWorld.sayHello(name); } + @Then("^It should return (.*)$") public void thenCheckOutput(String response) { - Assert.assertEquals(output, response); + Assertions.assertEquals(output, response); } - public static void main(String[] args) { } } diff --git a/jenkins/currency-exchange-microservice/src/test/java/com/in28minutes/microservices/currencyexchangeservice/cucumber/RunCucumberIntegrationTestCase.java b/jenkins/currency-exchange-microservice/src/test/java/com/in28minutes/microservices/currencyexchangeservice/cucumber/RunCucumberIntegrationTestCase.java index e25a67d6..33e9deb8 100755 --- a/jenkins/currency-exchange-microservice/src/test/java/com/in28minutes/microservices/currencyexchangeservice/cucumber/RunCucumberIntegrationTestCase.java +++ b/jenkins/currency-exchange-microservice/src/test/java/com/in28minutes/microservices/currencyexchangeservice/cucumber/RunCucumberIntegrationTestCase.java @@ -1,11 +1,9 @@ package com.in28minutes.microservices.currencyexchangeservice.cucumber; -import org.junit.runner.RunWith; +import io.cucumber.junit.CucumberOptions; +import io.cucumber.junit.platform.engine.Cucumber; -import cucumber.api.CucumberOptions; -import cucumber.api.junit.Cucumber; - -@RunWith(Cucumber.class) +@Cucumber @CucumberOptions(monochrome = true, features = "src/test/resources", plugin = { "pretty" }) public class RunCucumberIntegrationTestCase { } \ No newline at end of file diff --git a/jenkins/currency-exchange-microservice/src/test/java/com/in28minutes/microservices/currencyexchangeservice/resource/CurrencyExchangeControllerTest.java b/jenkins/currency-exchange-microservice/src/test/java/com/in28minutes/microservices/currencyexchangeservice/resource/CurrencyExchangeControllerTest.java index a6d671de..3938a23f 100755 --- a/jenkins/currency-exchange-microservice/src/test/java/com/in28minutes/microservices/currencyexchangeservice/resource/CurrencyExchangeControllerTest.java +++ b/jenkins/currency-exchange-microservice/src/test/java/com/in28minutes/microservices/currencyexchangeservice/resource/CurrencyExchangeControllerTest.java @@ -5,19 +5,15 @@ import java.math.BigDecimal; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import com.in28minutes.microservices.currencyexchangeservice.util.environment.InstanceInformationService; - -@RunWith(SpringRunner.class) @WebMvcTest(CurrencyExchangeController.class) public class CurrencyExchangeControllerTest { @Autowired diff --git a/kubernetes/01-hello-world-rest-api/.gitignore b/kubernetes/01-hello-world-rest-api/.gitignore new file mode 100644 index 00000000..723ef36f --- /dev/null +++ b/kubernetes/01-hello-world-rest-api/.gitignore @@ -0,0 +1 @@ +.idea \ No newline at end of file diff --git a/kubernetes/01-hello-world-rest-api/Dockerfile b/kubernetes/01-hello-world-rest-api/Dockerfile index 5daeea7b..3e889757 100644 --- a/kubernetes/01-hello-world-rest-api/Dockerfile +++ b/kubernetes/01-hello-world-rest-api/Dockerfile @@ -1,4 +1,4 @@ -FROM openjdk:8-jdk-alpine +FROM openjdk:21-jdk-slim VOLUME /tmp EXPOSE 8080 ADD target/*.jar app.jar diff --git a/kubernetes/01-hello-world-rest-api/pom.xml b/kubernetes/01-hello-world-rest-api/pom.xml index 01ab0ee9..23b7ce22 100644 --- a/kubernetes/01-hello-world-rest-api/pom.xml +++ b/kubernetes/01-hello-world-rest-api/pom.xml @@ -13,14 +13,14 @@ org.springframework.boot spring-boot-starter-parent - 2.1.7.RELEASE + 3.2.5 UTF-8 UTF-8 - 1.8 + 21 3.1.1 ${project.build.directory}/${project.build.finalName}.jar @@ -70,7 +70,6 @@ in28min/${project.name} ${project.version} - true diff --git a/kubernetes/01-hello-world-rest-api/src/test/java/com/in28minutes/rest/webservices/restfulwebservices/RestfulWebServicesApplicationTests.java b/kubernetes/01-hello-world-rest-api/src/test/java/com/in28minutes/rest/webservices/restfulwebservices/RestfulWebServicesApplicationTests.java index 55d01b98..65026f21 100644 --- a/kubernetes/01-hello-world-rest-api/src/test/java/com/in28minutes/rest/webservices/restfulwebservices/RestfulWebServicesApplicationTests.java +++ b/kubernetes/01-hello-world-rest-api/src/test/java/com/in28minutes/rest/webservices/restfulwebservices/RestfulWebServicesApplicationTests.java @@ -1,11 +1,11 @@ package com.in28minutes.rest.webservices.restfulwebservices; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; -@RunWith(SpringRunner.class) +@ExtendWith(MockitoExtension.class) @SpringBootTest public class RestfulWebServicesApplicationTests { diff --git a/projects/hello-world/hello-world-java/.gitignore b/projects/hello-world/hello-world-java/.gitignore new file mode 100644 index 00000000..723ef36f --- /dev/null +++ b/projects/hello-world/hello-world-java/.gitignore @@ -0,0 +1 @@ +.idea \ No newline at end of file diff --git a/projects/hello-world/hello-world-java/Dockerfile b/projects/hello-world/hello-world-java/Dockerfile index 1806cb58..1e269a39 100755 --- a/projects/hello-world/hello-world-java/Dockerfile +++ b/projects/hello-world/hello-world-java/Dockerfile @@ -1,11 +1,11 @@ # Build a JAR File -FROM maven:3.8.2-jdk-8-slim AS stage1 +FROM maven:3.9.6-amazoncorretto-21-al2023 AS stage1 WORKDIR /home/app COPY . /home/app/ RUN mvn -f /home/app/pom.xml clean package # Create an Image -FROM openjdk:8-jdk-alpine +FROM openjdk:21-jdk-slim EXPOSE 5000 COPY --from=stage1 /home/app/target/hello-world-java.jar hello-world-java.jar ENTRYPOINT ["sh", "-c", "java -jar /hello-world-java.jar"] diff --git a/projects/hello-world/hello-world-java/pom.xml b/projects/hello-world/hello-world-java/pom.xml index bfc77425..86a9fe7a 100755 --- a/projects/hello-world/hello-world-java/pom.xml +++ b/projects/hello-world/hello-world-java/pom.xml @@ -13,14 +13,14 @@ org.springframework.boot spring-boot-starter-parent - 2.1.7.RELEASE + 3.2.4 UTF-8 UTF-8 - 1.8 + 21 3.1.1 diff --git a/projects/hello-world/hello-world-java/src/test/java/com/in28minutes/rest/webservices/restfulwebservices/RestfulWebServicesApplicationTests.java b/projects/hello-world/hello-world-java/src/test/java/com/in28minutes/rest/webservices/restfulwebservices/RestfulWebServicesApplicationTests.java index 55d01b98..65026f21 100755 --- a/projects/hello-world/hello-world-java/src/test/java/com/in28minutes/rest/webservices/restfulwebservices/RestfulWebServicesApplicationTests.java +++ b/projects/hello-world/hello-world-java/src/test/java/com/in28minutes/rest/webservices/restfulwebservices/RestfulWebServicesApplicationTests.java @@ -1,11 +1,11 @@ package com.in28minutes.rest.webservices.restfulwebservices; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; -@RunWith(SpringRunner.class) +@ExtendWith(MockitoExtension.class) @SpringBootTest public class RestfulWebServicesApplicationTests { diff --git a/projects/microservices/01-currency-exchange-microservice-basic/Dockerfile b/projects/microservices/01-currency-exchange-microservice-basic/Dockerfile index 7d118172..3446147c 100755 --- a/projects/microservices/01-currency-exchange-microservice-basic/Dockerfile +++ b/projects/microservices/01-currency-exchange-microservice-basic/Dockerfile @@ -1,9 +1,9 @@ -FROM maven:3.8.2-jdk-8-slim AS build +FROM maven:3.9.6-amazoncorretto-21-al2023 AS build WORKDIR /home/app COPY . /home/app RUN mvn -f /home/app/pom.xml clean package -FROM openjdk:8-jdk-alpine +FROM openjdk:21-jdk-slim VOLUME /tmp EXPOSE 8000 COPY --from=build /home/app/target/*.jar app.jar diff --git a/projects/microservices/01-currency-exchange-microservice-basic/pom.xml b/projects/microservices/01-currency-exchange-microservice-basic/pom.xml index 1153ee5b..5de48d64 100755 --- a/projects/microservices/01-currency-exchange-microservice-basic/pom.xml +++ b/projects/microservices/01-currency-exchange-microservice-basic/pom.xml @@ -15,16 +15,16 @@ org.springframework.boot spring-boot-starter-parent - 2.1.1.RELEASE + 3.2.4 UTF-8 UTF-8 - 1.8 + 21 3.1.1 - Greenwich.SR3 + 2023.0.1 @@ -44,9 +44,10 @@ spring-boot-starter-security - - org.springframework.cloud - spring-cloud-starter-sleuth + + + io.micrometer + micrometer-tracing-bridge-brave @@ -59,6 +60,11 @@ spring-boot-devtools runtime + + org.junit.jupiter + junit-jupiter + test + com.h2database @@ -67,22 +73,17 @@ - javax.xml.bind - jaxb-api - - - com.sun.xml.bind - jaxb-impl - 2.3.1 + jakarta.xml.bind + jakarta.xml.bind-api org.glassfish.jaxb jaxb-runtime - javax.activation - activation - 1.1.1 + jakarta.activation + jakarta.activation-api + 1.2.2 diff --git a/projects/microservices/01-currency-exchange-microservice-basic/src/main/java/com/in28minutes/microservices/currencyexchangeservice/resource/CurrencyExchangeController.java b/projects/microservices/01-currency-exchange-microservice-basic/src/main/java/com/in28minutes/microservices/currencyexchangeservice/resource/CurrencyExchangeController.java index 5b305e3c..b0210003 100755 --- a/projects/microservices/01-currency-exchange-microservice-basic/src/main/java/com/in28minutes/microservices/currencyexchangeservice/resource/CurrencyExchangeController.java +++ b/projects/microservices/01-currency-exchange-microservice-basic/src/main/java/com/in28minutes/microservices/currencyexchangeservice/resource/CurrencyExchangeController.java @@ -50,7 +50,7 @@ public ExchangeValue retrieveExchangeValue(@PathVariable String from, @PathVaria private void printAllHeaders(Map headers) { headers.forEach((key, value) -> { - LOGGER.info(String.format("Header '%s' = %s", key, value)); + LOGGER.info("Header '%s' = %s".formatted(key, value)); }); } } diff --git a/projects/microservices/01-currency-exchange-microservice-basic/src/main/java/com/in28minutes/microservices/currencyexchangeservice/resource/ExchangeValue.java b/projects/microservices/01-currency-exchange-microservice-basic/src/main/java/com/in28minutes/microservices/currencyexchangeservice/resource/ExchangeValue.java index c119c267..55166e85 100755 --- a/projects/microservices/01-currency-exchange-microservice-basic/src/main/java/com/in28minutes/microservices/currencyexchangeservice/resource/ExchangeValue.java +++ b/projects/microservices/01-currency-exchange-microservice-basic/src/main/java/com/in28minutes/microservices/currencyexchangeservice/resource/ExchangeValue.java @@ -2,9 +2,9 @@ import java.math.BigDecimal; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; @Entity public class ExchangeValue { diff --git a/projects/microservices/01-currency-exchange-microservice-basic/src/main/java/com/in28minutes/microservices/currencyexchangeservice/security/SecurityConfiguration.java b/projects/microservices/01-currency-exchange-microservice-basic/src/main/java/com/in28minutes/microservices/currencyexchangeservice/security/SecurityConfiguration.java index dd509c4d..0211d5c8 100755 --- a/projects/microservices/01-currency-exchange-microservice-basic/src/main/java/com/in28minutes/microservices/currencyexchangeservice/security/SecurityConfiguration.java +++ b/projects/microservices/01-currency-exchange-microservice-basic/src/main/java/com/in28minutes/microservices/currencyexchangeservice/security/SecurityConfiguration.java @@ -1,18 +1,18 @@ package com.in28minutes.microservices.currencyexchangeservice.security; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.web.SecurityFilterChain; @Configuration -public class SecurityConfiguration extends WebSecurityConfigurerAdapter { +public class SecurityConfiguration { - @Override - protected void configure(HttpSecurity http) throws Exception { - http - .authorizeRequests().anyRequest().permitAll() - .and() - .httpBasic().disable() - .csrf().disable(); - } + @Bean + SecurityFilterChain filterChain(HttpSecurity http) throws Exception { + http.authorizeHttpRequests(auth -> auth.anyRequest().authenticated()) + .httpBasic(basic -> basic.disable()) + .csrf(csrf -> csrf.disable()); + return http.build(); + } } \ No newline at end of file diff --git a/projects/microservices/01-currency-exchange-microservice-basic/src/main/resources/application.properties b/projects/microservices/01-currency-exchange-microservice-basic/src/main/resources/application.properties index cf861c50..f2f1a729 100755 --- a/projects/microservices/01-currency-exchange-microservice-basic/src/main/resources/application.properties +++ b/projects/microservices/01-currency-exchange-microservice-basic/src/main/resources/application.properties @@ -15,5 +15,7 @@ spring.security.user.password=dummy #Feign and Ribbon Timeouts feign.client.config.default.connectTimeout=50000 feign.client.config.default.readTimeout=50000 +# Logging pattern containing traceId and spanId; no longer provided through Sleuth by default +logging.pattern.level="%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-}]" ribbon.ConnectTimeout= 60000 ribbon.ReadTimeout= 60000 \ No newline at end of file diff --git a/projects/microservices/01-currency-exchange-microservice-basic/src/test/java/com/in28minutes/microservices/currencyexchangeservice/CurrencyExchangeServiceApplicationTests.java b/projects/microservices/01-currency-exchange-microservice-basic/src/test/java/com/in28minutes/microservices/currencyexchangeservice/CurrencyExchangeServiceApplicationTests.java index f4f82fe1..67b1a020 100755 --- a/projects/microservices/01-currency-exchange-microservice-basic/src/test/java/com/in28minutes/microservices/currencyexchangeservice/CurrencyExchangeServiceApplicationTests.java +++ b/projects/microservices/01-currency-exchange-microservice-basic/src/test/java/com/in28minutes/microservices/currencyexchangeservice/CurrencyExchangeServiceApplicationTests.java @@ -1,11 +1,8 @@ package com.in28minutes.microservices.currencyexchangeservice; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; -@RunWith(SpringRunner.class) @SpringBootTest public class CurrencyExchangeServiceApplicationTests { diff --git a/projects/microservices/02-currency-conversion-microservice-basic/.gitignore b/projects/microservices/02-currency-conversion-microservice-basic/.gitignore new file mode 100644 index 00000000..485dee64 --- /dev/null +++ b/projects/microservices/02-currency-conversion-microservice-basic/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/projects/microservices/02-currency-conversion-microservice-basic/Dockerfile b/projects/microservices/02-currency-conversion-microservice-basic/Dockerfile index aea2f185..46f41b07 100755 --- a/projects/microservices/02-currency-conversion-microservice-basic/Dockerfile +++ b/projects/microservices/02-currency-conversion-microservice-basic/Dockerfile @@ -1,9 +1,9 @@ -FROM maven:3.8.2-jdk-8-slim AS build +FROM maven:3.9.6-amazoncorretto-21-al2023 AS build WORKDIR /home/app COPY . /home/app RUN mvn -f /home/app/pom.xml clean package -FROM openjdk:8-jdk-alpine +FROM openjdk:21-jdk-slim VOLUME /tmp EXPOSE 8100 COPY --from=build /home/app/target/*.jar app.jar diff --git a/projects/microservices/02-currency-conversion-microservice-basic/pom.xml b/projects/microservices/02-currency-conversion-microservice-basic/pom.xml index ca432909..9d8db7c2 100755 --- a/projects/microservices/02-currency-conversion-microservice-basic/pom.xml +++ b/projects/microservices/02-currency-conversion-microservice-basic/pom.xml @@ -15,16 +15,16 @@ org.springframework.boot spring-boot-starter-parent - 2.1.7.RELEASE + 3.2.4 UTF-8 UTF-8 - 1.8 + 21 3.1.1 - Greenwich.SR3 + 2023.0.1 @@ -49,9 +49,10 @@ spring-boot-starter-security + - org.springframework.cloud - spring-cloud-starter-sleuth + io.micrometer + micrometer-tracing-bridge-brave