From 6ff926e003358723afb8c5be8a9351047cc5d8ed Mon Sep 17 00:00:00 2001 From: timis1 <12120641+timis1@users.noreply.github.com> Date: Sat, 30 Mar 2024 19:42:52 +0200 Subject: [PATCH] JAVA-32053 Upgrade spring-mvc-basics-3 to Spring Boot 3 (#16231) Co-authored-by: timis1 --- .../spring-mvc-basics-3/pom.xml | 13 ++++------ .../java/com/baeldung/boot/Application.java | 4 +--- .../controller/GenericEntityController.java | 2 +- .../converter/GenericBigDecimalConverter.java | 2 +- .../com/baeldung/boot/domain/Employee.java | 4 ++-- .../java/com/baeldung/boot/domain/Foo.java | 3 ++- .../baeldung/boot/domain/GenericEntity.java | 8 +++---- .../HeaderVersionArgumentResolver.java | 2 +- .../CachedBodyHttpServletRequest.java | 6 ++--- .../CachedBodyServletInputStream.java | 4 ++-- .../cachedrequest/ContentCachingFilter.java | 10 ++++---- .../cachedrequest/HttpRequestDemoConfig.java | 4 +--- .../PrintRequestContentFilter.java | 13 +++++----- .../ContactNumberConstraint.java | 4 ++-- .../ContactNumberValidator.java | 4 ++-- .../customvalidator/FieldsValueMatch.java | 4 ++-- .../FieldsValueMatchValidator.java | 4 ++-- .../customvalidator/NewUserController.java | 2 +- .../ValidatedPhoneController.java | 2 +- .../controllers/PoemSubmission.java | 2 +- .../interpolation/MyMessageInterpolator.java | 6 +---- .../interpolation/NotNullRequest.java | 2 +- .../interpolation/ValidationController.java | 2 +- .../interpolation/ValidationExamples.java | 9 +++---- .../controller/ReadHeaderRestController.java | 24 ++++++++----------- .../SpringBootMailIntegrationTest.java | 16 ++++++------- .../CachedBodyServletInputStreamUnitTest.java | 6 ++--- .../ContentCachingFilterUnitTest.java | 4 ++-- .../PrintRequestContentFilterUnitTest.java | 4 ++-- 29 files changed, 75 insertions(+), 95 deletions(-) diff --git a/spring-web-modules/spring-mvc-basics-3/pom.xml b/spring-web-modules/spring-mvc-basics-3/pom.xml index 7e0d741619..b38c1a493d 100644 --- a/spring-web-modules/spring-mvc-basics-3/pom.xml +++ b/spring-web-modules/spring-mvc-basics-3/pom.xml @@ -10,9 +10,9 @@ com.baeldung - parent-boot-2 + parent-boot-3 0.0.1-SNAPSHOT - ../../parent-boot-2 + ../../parent-boot-3 @@ -51,18 +51,13 @@ h2 runtime - - javax.persistence - javax.persistence-api - ${jpa.version} - com.google.guava guava ${guava.version} - org.subethamail + com.github.davidmoten subethasmtp ${subethasmtp.version} test @@ -130,7 +125,7 @@ 3.1.1 3.3.7-1 2.2 - 3.1.7 + 7.0.2 4.5.8 diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/Application.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/Application.java index cb0d0c1532..a78bb0410b 100644 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/Application.java +++ b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/Application.java @@ -2,13 +2,11 @@ package com.baeldung.boot; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.ApplicationContext; @SpringBootApplication public class Application { - private static ApplicationContext applicationContext; public static void main(String[] args) { - applicationContext = SpringApplication.run(Application.class, args); + SpringApplication.run(Application.class, args); } } diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/controller/GenericEntityController.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/controller/GenericEntityController.java index 39fd5af318..fdfe005518 100644 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/controller/GenericEntityController.java +++ b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/controller/GenericEntityController.java @@ -53,6 +53,6 @@ public class GenericEntityController { @GetMapping("/entity/findbyversion") public ResponseEntity findByVersion(@Version String version) { - return version != null ? new ResponseEntity(entityList.stream().findFirst().get(), HttpStatus.OK) : new ResponseEntity(HttpStatus.NOT_FOUND); + return version != null ? new ResponseEntity<>(entityList.stream().findFirst().get(), HttpStatus.OK) : new ResponseEntity<>(HttpStatus.NOT_FOUND); } } diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/converter/GenericBigDecimalConverter.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/converter/GenericBigDecimalConverter.java index 0040327e00..022b03ff0d 100644 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/converter/GenericBigDecimalConverter.java +++ b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/converter/GenericBigDecimalConverter.java @@ -27,7 +27,7 @@ public class GenericBigDecimalConverter implements GenericConverter { return new BigDecimal(number); } else { Number number = (Number) source; - BigDecimal converted = new BigDecimal(number.doubleValue()); + BigDecimal converted = BigDecimal.valueOf(number.doubleValue()); return converted.setScale(2, BigDecimal.ROUND_HALF_EVEN); } } diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/domain/Employee.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/domain/Employee.java index a96fc5d051..22a28b9fd7 100644 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/domain/Employee.java +++ b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/domain/Employee.java @@ -1,7 +1,7 @@ package com.baeldung.boot.domain; -import javax.persistence.Entity; -import javax.persistence.Id; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; @Entity public class Employee { diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/domain/Foo.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/domain/Foo.java index c6637f6162..26fbe54921 100644 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/domain/Foo.java +++ b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/domain/Foo.java @@ -1,6 +1,7 @@ package com.baeldung.boot.domain; -import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric; +import static org.thymeleaf.util.StringUtils.randomAlphanumeric; + public class Foo extends AbstractEntity { private String name; diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/domain/GenericEntity.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/domain/GenericEntity.java index a2a676200a..ba38aadeef 100644 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/domain/GenericEntity.java +++ b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/domain/GenericEntity.java @@ -1,9 +1,9 @@ package com.baeldung.boot.domain; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; @Entity public class GenericEntity { diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/web/resolver/HeaderVersionArgumentResolver.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/web/resolver/HeaderVersionArgumentResolver.java index de10fa5098..8b012432ed 100644 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/web/resolver/HeaderVersionArgumentResolver.java +++ b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/boot/web/resolver/HeaderVersionArgumentResolver.java @@ -7,7 +7,7 @@ import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.method.support.ModelAndViewContainer; -import javax.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletRequest; @Component public class HeaderVersionArgumentResolver implements HandlerMethodArgumentResolver { diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/CachedBodyHttpServletRequest.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/CachedBodyHttpServletRequest.java index 89acbe79a4..9e79b5fa42 100644 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/CachedBodyHttpServletRequest.java +++ b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/CachedBodyHttpServletRequest.java @@ -6,9 +6,9 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import javax.servlet.ServletInputStream; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletRequestWrapper; +import jakarta.servlet.ServletInputStream; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletRequestWrapper; import org.springframework.util.StreamUtils; diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/CachedBodyServletInputStream.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/CachedBodyServletInputStream.java index 4d44b23ee9..6ae681d088 100644 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/CachedBodyServletInputStream.java +++ b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/CachedBodyServletInputStream.java @@ -4,8 +4,8 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import javax.servlet.ReadListener; -import javax.servlet.ServletInputStream; +import jakarta.servlet.ReadListener; +import jakarta.servlet.ServletInputStream; public class CachedBodyServletInputStream extends ServletInputStream { diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/ContentCachingFilter.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/ContentCachingFilter.java index ba3901077b..75c73b509c 100644 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/ContentCachingFilter.java +++ b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/ContentCachingFilter.java @@ -2,11 +2,11 @@ package com.baeldung.cachedrequest; import java.io.IOException; -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.annotation.WebFilter; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebFilter; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/HttpRequestDemoConfig.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/HttpRequestDemoConfig.java index 9516ff861e..6e40540d01 100644 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/HttpRequestDemoConfig.java +++ b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/HttpRequestDemoConfig.java @@ -5,10 +5,8 @@ import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; /** - * To initialize the WebApplication, Please see - * {@link com.baeldung.spring.config.MainWebAppInitializer} + * To initialize the WebApplication */ - @EnableWebMvc @Configuration @ComponentScan(basePackages = "com.baeldung.cachedrequest") diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/PrintRequestContentFilter.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/PrintRequestContentFilter.java index 9c4c589a5d..bf1de0573f 100644 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/PrintRequestContentFilter.java +++ b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/cachedrequest/PrintRequestContentFilter.java @@ -4,19 +4,18 @@ package com.baeldung.cachedrequest; import java.io.IOException; import java.io.InputStream; -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.annotation.WebFilter; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebFilter; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; -import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; import org.springframework.util.StreamUtils; import org.springframework.web.filter.OncePerRequestFilter; -@Order(Ordered.LOWEST_PRECEDENCE) +@Order @Component @WebFilter(filterName = "printRequestContentFilter", urlPatterns = "/*") public class PrintRequestContentFilter extends OncePerRequestFilter { diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/customvalidator/ContactNumberConstraint.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/customvalidator/ContactNumberConstraint.java index 42e441f8f9..525c1096a1 100644 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/customvalidator/ContactNumberConstraint.java +++ b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/customvalidator/ContactNumberConstraint.java @@ -6,8 +6,8 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import javax.validation.Constraint; -import javax.validation.Payload; +import jakarta.validation.Constraint; +import jakarta.validation.Payload; @Documented @Constraint(validatedBy = ContactNumberValidator.class) diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/customvalidator/ContactNumberValidator.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/customvalidator/ContactNumberValidator.java index fe14f3ccf1..6436bef8fd 100644 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/customvalidator/ContactNumberValidator.java +++ b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/customvalidator/ContactNumberValidator.java @@ -1,7 +1,7 @@ package com.baeldung.customvalidator; -import javax.validation.ConstraintValidator; -import javax.validation.ConstraintValidatorContext; +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; public class ContactNumberValidator implements ConstraintValidator { diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/customvalidator/FieldsValueMatch.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/customvalidator/FieldsValueMatch.java index 51db279f0b..2714f2cdef 100644 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/customvalidator/FieldsValueMatch.java +++ b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/customvalidator/FieldsValueMatch.java @@ -5,8 +5,8 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import javax.validation.Constraint; -import javax.validation.Payload; +import jakarta.validation.Constraint; +import jakarta.validation.Payload; @Constraint(validatedBy = FieldsValueMatchValidator.class) @Target({ ElementType.TYPE }) diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/customvalidator/FieldsValueMatchValidator.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/customvalidator/FieldsValueMatchValidator.java index c3e8533ec9..e807a9b649 100644 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/customvalidator/FieldsValueMatchValidator.java +++ b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/customvalidator/FieldsValueMatchValidator.java @@ -1,7 +1,7 @@ package com.baeldung.customvalidator; -import javax.validation.ConstraintValidator; -import javax.validation.ConstraintValidatorContext; +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; import org.springframework.beans.BeanWrapperImpl; diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/customvalidator/NewUserController.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/customvalidator/NewUserController.java index 040dcf1a85..27aac68adc 100644 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/customvalidator/NewUserController.java +++ b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/customvalidator/NewUserController.java @@ -1,6 +1,6 @@ package com.baeldung.customvalidator; -import javax.validation.Valid; +import jakarta.validation.Valid; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/customvalidator/ValidatedPhoneController.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/customvalidator/ValidatedPhoneController.java index be347a6777..9f23c5b14d 100644 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/customvalidator/ValidatedPhoneController.java +++ b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/customvalidator/ValidatedPhoneController.java @@ -1,6 +1,6 @@ package com.baeldung.customvalidator; -import javax.validation.Valid; +import jakarta.validation.Valid; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/flash_attributes/controllers/PoemSubmission.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/flash_attributes/controllers/PoemSubmission.java index 6264ea0531..c37a26749d 100644 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/flash_attributes/controllers/PoemSubmission.java +++ b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/flash_attributes/controllers/PoemSubmission.java @@ -11,7 +11,7 @@ import org.springframework.web.servlet.support.RequestContextUtils; import org.springframework.web.servlet.view.RedirectView; import java.util.Map; -import javax.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletRequest; @Controller public class PoemSubmission { diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/interpolation/MyMessageInterpolator.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/interpolation/MyMessageInterpolator.java index efa3d62b88..c5a2fc868a 100644 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/interpolation/MyMessageInterpolator.java +++ b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/interpolation/MyMessageInterpolator.java @@ -1,14 +1,10 @@ package com.baeldung.interpolation; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import javax.validation.MessageInterpolator; +import jakarta.validation.MessageInterpolator; import java.util.Locale; public class MyMessageInterpolator implements MessageInterpolator { - private static Logger logger = LoggerFactory.getLogger(MyMessageInterpolator.class); - private final MessageInterpolator defaultInterpolator; public MyMessageInterpolator(MessageInterpolator interpolator) { diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/interpolation/NotNullRequest.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/interpolation/NotNullRequest.java index 9a2b00be8f..2bf1e2e45a 100644 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/interpolation/NotNullRequest.java +++ b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/interpolation/NotNullRequest.java @@ -1,6 +1,6 @@ package com.baeldung.interpolation; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.NotNull; public class NotNullRequest { diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/interpolation/ValidationController.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/interpolation/ValidationController.java index 3fed170fdf..5637d2eba2 100644 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/interpolation/ValidationController.java +++ b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/interpolation/ValidationController.java @@ -1,6 +1,6 @@ package com.baeldung.interpolation; -import javax.validation.Valid; +import jakarta.validation.Valid; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/interpolation/ValidationExamples.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/interpolation/ValidationExamples.java index 6c9b924200..53d3e577c8 100644 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/interpolation/ValidationExamples.java +++ b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/interpolation/ValidationExamples.java @@ -1,14 +1,11 @@ package com.baeldung.interpolation; -import java.util.Formatter; -import javax.validation.constraints.Size; -import javax.validation.constraints.Min; -import javax.validation.constraints.DecimalMin; +import jakarta.validation.constraints.DecimalMin; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.Size; public class ValidationExamples { - private static final Formatter formatter = new Formatter(); - @Size( min = 5, max = 14, diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/spring/headers/controller/ReadHeaderRestController.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/spring/headers/controller/ReadHeaderRestController.java index ff4d0eea58..7106b3f5bc 100644 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/spring/headers/controller/ReadHeaderRestController.java +++ b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/spring/headers/controller/ReadHeaderRestController.java @@ -22,7 +22,7 @@ public class ReadHeaderRestController { @GetMapping("/") public ResponseEntity index() { - return new ResponseEntity("Index", HttpStatus.OK); + return new ResponseEntity<>("Index", HttpStatus.OK); } @GetMapping("/greeting") @@ -46,12 +46,12 @@ public class ReadHeaderRestController { break; } - return new ResponseEntity(greeting, HttpStatus.OK); + return new ResponseEntity<>(greeting, HttpStatus.OK); } @GetMapping("/double") public ResponseEntity doubleNumber(@RequestHeader("my-number") int myNumber) { - return new ResponseEntity( + return new ResponseEntity<>( String.format("%d * 2 = %d", myNumber, (myNumber * 2)), HttpStatus.OK); } @@ -59,34 +59,30 @@ public class ReadHeaderRestController { @GetMapping("/listHeaders") public ResponseEntity listAllHeaders(@RequestHeader Map headers) { - headers.forEach((key, value) -> { - LOG.info(String.format("Header '%s' = %s", key, value)); - }); + headers.forEach((key, value) -> LOG.info(String.format("Header '%s' = %s", key, value))); - return new ResponseEntity(String.format("Listed %d headers", headers.size()), HttpStatus.OK); + return new ResponseEntity<>(String.format("Listed %d headers", headers.size()), HttpStatus.OK); } @GetMapping("/multiValue") public ResponseEntity multiValue(@RequestHeader MultiValueMap headers) { - headers.forEach((key, value) -> { - LOG.info(String.format("Header '%s' = %s", key, value.stream().collect(Collectors.joining("|")))); - }); + headers.forEach((key, value) -> LOG.info(String.format("Header '%s' = %s", key, String.join("|", value)))); - return new ResponseEntity(String.format("Listed %d headers", headers.size()), HttpStatus.OK); + return new ResponseEntity<>(String.format("Listed %d headers", headers.size()), HttpStatus.OK); } @GetMapping("/getBaseUrl") public ResponseEntity getBaseUrl(@RequestHeader HttpHeaders headers) { InetSocketAddress host = headers.getHost(); String url = "http://" + host.getHostName() + ":" + host.getPort(); - return new ResponseEntity(String.format("Base URL = %s", url), HttpStatus.OK); + return new ResponseEntity<>(String.format("Base URL = %s", url), HttpStatus.OK); } @GetMapping("/nonRequiredHeader") public ResponseEntity evaluateNonRequiredHeader( @RequestHeader(value = "optional-header", required = false) String optionalHeader) { - return new ResponseEntity( + return new ResponseEntity<>( String.format("Was the optional header present? %s!", (optionalHeader == null ? "No" : "Yes")), HttpStatus.OK); } @@ -95,6 +91,6 @@ public class ReadHeaderRestController { public ResponseEntity evaluateDefaultHeaderValue( @RequestHeader(value = "optional-header", defaultValue = "3600") int optionalHeader) { - return new ResponseEntity(String.format("Optional Header is %d", optionalHeader), HttpStatus.OK); + return new ResponseEntity<>(String.format("Optional Header is %d", optionalHeader), HttpStatus.OK); } } diff --git a/spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/SpringBootMailIntegrationTest.java b/spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/SpringBootMailIntegrationTest.java index 1349e7e9e0..4d4ac784b3 100644 --- a/spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/SpringBootMailIntegrationTest.java +++ b/spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/SpringBootMailIntegrationTest.java @@ -13,7 +13,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.subethamail.wiser.Wiser; import org.subethamail.wiser.WiserMessage; -import javax.mail.MessagingException; +import jakarta.mail.MessagingException; import java.io.IOException; import java.util.List; @@ -29,20 +29,20 @@ public class SpringBootMailIntegrationTest { private Wiser wiser; - private String userTo = "user2@localhost"; - private String userFrom = "user1@localhost"; - private String subject = "Test subject"; - private String textMail = "Text subject mail"; + private final String userTo = "user2@localhost"; + private final String userFrom = "user1@localhost"; + private final String subject = "Test subject"; + private final String textMail = "Text subject mail"; @Before - public void setUp() throws Exception { + public void setUp() { final int TEST_PORT = 8025; - wiser = new Wiser(TEST_PORT); + wiser = Wiser.port(TEST_PORT); wiser.start(); } @After - public void tearDown() throws Exception { + public void tearDown() { wiser.stop(); } diff --git a/spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/cachedrequest/CachedBodyServletInputStreamUnitTest.java b/spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/cachedrequest/CachedBodyServletInputStreamUnitTest.java index af025f632e..21f8854bdf 100644 --- a/spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/cachedrequest/CachedBodyServletInputStreamUnitTest.java +++ b/spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/cachedrequest/CachedBodyServletInputStreamUnitTest.java @@ -3,7 +3,7 @@ package com.baeldung.cachedrequest; import java.io.ByteArrayOutputStream; import java.io.IOException; -import javax.servlet.ReadListener; +import jakarta.servlet.ReadListener; import org.junit.After; import org.junit.Test; @@ -54,7 +54,7 @@ public class CachedBodyServletInputStreamUnitTest extends TestCase { } @Test - public void testGivenServletInputStreamCreatedAndBodyRead_whenCalledIsReady_ThenTrue() throws IOException { + public void testGivenServletInputStreamCreatedAndBodyRead_whenCalledIsReady_ThenTrue() { // Given byte[] cachedBody = "{\"firstName\" :\"abc\",\"lastName\" : \"xyz\",\"age\" : 30\"}".getBytes(); servletInputStream = new CachedBodyServletInputStream(cachedBody); @@ -85,7 +85,7 @@ public class CachedBodyServletInputStreamUnitTest extends TestCase { } @Test(expected = UnsupportedOperationException.class) - public void testGivenServletInputStreamCreated_whenCalledIsRead_ThenThrowsException() throws IOException { + public void testGivenServletInputStreamCreated_whenCalledIsRead_ThenThrowsException() { // Given byte[] cachedBody = "{\"firstName\" :\"abc\",\"lastName\" : \"xyz\",\"age\" : 30\"}".getBytes(); servletInputStream = new CachedBodyServletInputStream(cachedBody); diff --git a/spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/cachedrequest/ContentCachingFilterUnitTest.java b/spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/cachedrequest/ContentCachingFilterUnitTest.java index ec0f8948c2..26c3fd37a0 100644 --- a/spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/cachedrequest/ContentCachingFilterUnitTest.java +++ b/spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/cachedrequest/ContentCachingFilterUnitTest.java @@ -2,8 +2,8 @@ package com.baeldung.cachedrequest; import java.io.IOException; -import javax.servlet.FilterChain; -import javax.servlet.ServletException; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/cachedrequest/PrintRequestContentFilterUnitTest.java b/spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/cachedrequest/PrintRequestContentFilterUnitTest.java index 3d2acabe6b..b694c5220b 100644 --- a/spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/cachedrequest/PrintRequestContentFilterUnitTest.java +++ b/spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/cachedrequest/PrintRequestContentFilterUnitTest.java @@ -2,8 +2,8 @@ package com.baeldung.cachedrequest; import java.io.IOException; -import javax.servlet.FilterChain; -import javax.servlet.ServletException; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; import org.junit.Test; import org.junit.runner.RunWith;