diff --git a/aws-lambda/lambda/pom.xml b/aws-lambda/lambda/pom.xml
new file mode 100644
index 0000000000..2d903aabc5
--- /dev/null
+++ b/aws-lambda/lambda/pom.xml
@@ -0,0 +1,100 @@
+
+
+ 4.0.0
+ aws-lambda-examples
+ 0.1.0-SNAPSHOT
+ aws-lambda-examples
+ jar
+
+
+ com.baeldung
+ parent-modules
+ 1.0.0-SNAPSHOT
+ ../../
+
+
+
+
+ com.amazonaws
+ aws-java-sdk-dynamodb
+ ${aws-java-sdk.version}
+
+
+ com.amazonaws
+ aws-java-sdk-core
+ ${aws-java-sdk.version}
+
+
+ com.amazonaws
+ aws-lambda-java-core
+ ${aws-lambda-java-core.version}
+
+
+ commons-logging
+ commons-logging
+
+
+
+
+ com.amazonaws
+ aws-lambda-java-events
+ ${aws-lambda-java-events.version}
+
+
+ commons-logging
+ commons-logging
+
+
+
+
+ com.google.code.gson
+ gson
+ ${gson.version}
+
+
+ commons-io
+ commons-io
+ ${commons-io.version}
+
+
+ com.googlecode.json-simple
+ json-simple
+ ${json-simple.version}
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+ ${maven-shade-plugin.version}
+
+ false
+
+
+
+ package
+
+ shade
+
+
+
+
+
+
+
+
+ 1.1.1
+ 2.5
+ 1.3.0
+ 1.2.0
+ 2.8.2
+ 1.11.241
+ 3.0.0
+
+
+
diff --git a/aws-lambda/sam-templates/template-implicit.yaml b/aws-lambda/lambda/sam-templates/template-implicit.yaml
similarity index 100%
rename from aws-lambda/sam-templates/template-implicit.yaml
rename to aws-lambda/lambda/sam-templates/template-implicit.yaml
diff --git a/aws-lambda/sam-templates/template-inline-swagger.yaml b/aws-lambda/lambda/sam-templates/template-inline-swagger.yaml
similarity index 100%
rename from aws-lambda/sam-templates/template-inline-swagger.yaml
rename to aws-lambda/lambda/sam-templates/template-inline-swagger.yaml
diff --git a/aws-lambda/src/main/java/com/baeldung/lambda/LambdaMethodHandler.java b/aws-lambda/lambda/src/main/java/com/baeldung/lambda/LambdaMethodHandler.java
similarity index 100%
rename from aws-lambda/src/main/java/com/baeldung/lambda/LambdaMethodHandler.java
rename to aws-lambda/lambda/src/main/java/com/baeldung/lambda/LambdaMethodHandler.java
diff --git a/aws-lambda/src/main/java/com/baeldung/lambda/LambdaRequestHandler.java b/aws-lambda/lambda/src/main/java/com/baeldung/lambda/LambdaRequestHandler.java
similarity index 100%
rename from aws-lambda/src/main/java/com/baeldung/lambda/LambdaRequestHandler.java
rename to aws-lambda/lambda/src/main/java/com/baeldung/lambda/LambdaRequestHandler.java
diff --git a/aws-lambda/src/main/java/com/baeldung/lambda/LambdaRequestStreamHandler.java b/aws-lambda/lambda/src/main/java/com/baeldung/lambda/LambdaRequestStreamHandler.java
similarity index 100%
rename from aws-lambda/src/main/java/com/baeldung/lambda/LambdaRequestStreamHandler.java
rename to aws-lambda/lambda/src/main/java/com/baeldung/lambda/LambdaRequestStreamHandler.java
diff --git a/aws-lambda/src/main/java/com/baeldung/lambda/apigateway/APIDemoHandler.java b/aws-lambda/lambda/src/main/java/com/baeldung/lambda/apigateway/APIDemoHandler.java
similarity index 100%
rename from aws-lambda/src/main/java/com/baeldung/lambda/apigateway/APIDemoHandler.java
rename to aws-lambda/lambda/src/main/java/com/baeldung/lambda/apigateway/APIDemoHandler.java
diff --git a/aws-lambda/src/main/java/com/baeldung/lambda/apigateway/model/Person.java b/aws-lambda/lambda/src/main/java/com/baeldung/lambda/apigateway/model/Person.java
similarity index 100%
rename from aws-lambda/src/main/java/com/baeldung/lambda/apigateway/model/Person.java
rename to aws-lambda/lambda/src/main/java/com/baeldung/lambda/apigateway/model/Person.java
diff --git a/aws-lambda/src/main/java/com/baeldung/lambda/dynamodb/SavePersonHandler.java b/aws-lambda/lambda/src/main/java/com/baeldung/lambda/dynamodb/SavePersonHandler.java
similarity index 100%
rename from aws-lambda/src/main/java/com/baeldung/lambda/dynamodb/SavePersonHandler.java
rename to aws-lambda/lambda/src/main/java/com/baeldung/lambda/dynamodb/SavePersonHandler.java
diff --git a/aws-lambda/src/main/java/com/baeldung/lambda/dynamodb/bean/PersonRequest.java b/aws-lambda/lambda/src/main/java/com/baeldung/lambda/dynamodb/bean/PersonRequest.java
similarity index 100%
rename from aws-lambda/src/main/java/com/baeldung/lambda/dynamodb/bean/PersonRequest.java
rename to aws-lambda/lambda/src/main/java/com/baeldung/lambda/dynamodb/bean/PersonRequest.java
diff --git a/aws-lambda/src/main/java/com/baeldung/lambda/dynamodb/bean/PersonResponse.java b/aws-lambda/lambda/src/main/java/com/baeldung/lambda/dynamodb/bean/PersonResponse.java
similarity index 100%
rename from aws-lambda/src/main/java/com/baeldung/lambda/dynamodb/bean/PersonResponse.java
rename to aws-lambda/lambda/src/main/java/com/baeldung/lambda/dynamodb/bean/PersonResponse.java
diff --git a/aws-lambda/src/main/resources/logback.xml b/aws-lambda/lambda/src/main/resources/logback.xml
similarity index 100%
rename from aws-lambda/src/main/resources/logback.xml
rename to aws-lambda/lambda/src/main/resources/logback.xml
diff --git a/aws-lambda/pom.xml b/aws-lambda/pom.xml
index e1d2c7df27..116fc801aa 100644
--- a/aws-lambda/pom.xml
+++ b/aws-lambda/pom.xml
@@ -5,95 +5,19 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
aws-lambda
- 0.1.0-SNAPSHOT
aws-lambda
- jar
+ pom
com.baeldung
parent-modules
1.0.0-SNAPSHOT
+ ../
-
-
- com.amazonaws
- aws-java-sdk-dynamodb
- ${aws-java-sdk.version}
-
-
- com.amazonaws
- aws-java-sdk-core
- ${aws-java-sdk.version}
-
-
- com.amazonaws
- aws-lambda-java-core
- ${aws-lambda-java-core.version}
-
-
- commons-logging
- commons-logging
-
-
-
-
- com.amazonaws
- aws-lambda-java-events
- ${aws-lambda-java-events.version}
-
-
- commons-logging
- commons-logging
-
-
-
-
- com.google.code.gson
- gson
- ${gson.version}
-
-
- commons-io
- commons-io
- ${commons-io.version}
-
-
- com.googlecode.json-simple
- json-simple
- ${json-simple.version}
-
-
+
+ lambda
+ shipping-tracker/ShippingFunction
+
-
-
-
- org.apache.maven.plugins
- maven-shade-plugin
- ${maven-shade-plugin.version}
-
- false
-
-
-
- package
-
- shade
-
-
-
-
-
-
-
-
- 1.1.1
- 2.5
- 1.3.0
- 1.2.0
- 2.8.2
- 1.11.241
- 3.0.0
-
-
-
\ No newline at end of file
+
diff --git a/aws-lambda/shipping-tracker/.gitignore b/aws-lambda/shipping-tracker/.gitignore
new file mode 100644
index 0000000000..9984c2e554
--- /dev/null
+++ b/aws-lambda/shipping-tracker/.gitignore
@@ -0,0 +1 @@
+.aws-sam/
diff --git a/aws-lambda/shipping-tracker/ShippingFunction/pom.xml b/aws-lambda/shipping-tracker/ShippingFunction/pom.xml
new file mode 100644
index 0000000000..ac39c9ea54
--- /dev/null
+++ b/aws-lambda/shipping-tracker/ShippingFunction/pom.xml
@@ -0,0 +1,73 @@
+
+ 4.0.0
+ com.baeldung
+ ShippingFunction
+ 1.0
+ jar
+ Shipping Tracker Lambda Function
+
+ 1.8
+ 1.8
+ 5.4.21.Final
+
+
+
+
+ com.amazonaws
+ aws-lambda-java-core
+ 1.2.0
+
+
+ com.amazonaws
+ aws-lambda-java-events
+ 3.1.0
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+ 2.11.2
+
+
+ junit
+ junit
+ 4.12
+ test
+
+
+ org.hibernate
+ hibernate-core
+ ${hibernate.version}
+
+
+ org.hibernate
+ hibernate-hikaricp
+ ${hibernate.version}
+
+
+ org.postgresql
+ postgresql
+ 42.2.16
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+ 3.1.1
+
+
+
+
+ package
+
+ shade
+
+
+
+
+
+
+
diff --git a/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/App.java b/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/App.java
new file mode 100644
index 0000000000..719725598c
--- /dev/null
+++ b/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/App.java
@@ -0,0 +1,108 @@
+package com.baeldung.lambda.shipping;
+
+import com.amazonaws.services.lambda.runtime.Context;
+import com.amazonaws.services.lambda.runtime.RequestHandler;
+import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
+import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.hibernate.SessionFactory;
+import org.hibernate.boot.MetadataSources;
+import org.hibernate.boot.registry.StandardServiceRegistry;
+import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.hibernate.cfg.AvailableSettings.*;
+import static org.hibernate.cfg.AvailableSettings.PASS;
+
+/**
+ * Handler for requests to Lambda function.
+ */
+public class App implements RequestHandler {
+private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+
+ public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context) {
+ try (SessionFactory sessionFactory = createSessionFactory()) {
+ ShippingService service = new ShippingService(sessionFactory, new ShippingDao());
+ return routeRequest(input, service);
+ }
+ }
+
+ private APIGatewayProxyResponseEvent routeRequest(APIGatewayProxyRequestEvent input, ShippingService service) {
+ Map headers = new HashMap<>();
+ headers.put("Content-Type", "application/json");
+ headers.put("X-Custom-Header", "application/json");
+
+ Object result = "OK";
+
+ switch (input.getResource()) {
+ case "/consignment":
+ result = service.createConsignment(
+ fromJson(input.getBody(), Consignment.class));
+ break;
+ case "/consignment/{id}":
+ result = service.view(input.getPathParameters().get("id"));
+ break;
+ case "/consignment/{id}/item":
+ service.addItem(input.getPathParameters().get("id"),
+ fromJson(input.getBody(), Item.class));
+ break;
+ case "/consignment/{id}/checkin":
+ service.checkIn(input.getPathParameters().get("id"),
+ fromJson(input.getBody(), Checkin.class));
+ break;
+ }
+
+ return new APIGatewayProxyResponseEvent()
+ .withHeaders(headers)
+ .withStatusCode(200)
+ .withBody(toJson(result));
+ }
+
+ private static String toJson(T object) {
+ try {
+ return OBJECT_MAPPER.writeValueAsString(object);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private static T fromJson(String json, Class type) {
+ try {
+ return OBJECT_MAPPER.readValue(json, type);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private static SessionFactory createSessionFactory() {
+ Map settings = new HashMap<>();
+ settings.put(URL, System.getenv("DB_URL"));
+ settings.put(DIALECT, "org.hibernate.dialect.PostgreSQLDialect");
+ settings.put(DEFAULT_SCHEMA, "shipping");
+ settings.put(DRIVER, "org.postgresql.Driver");
+ settings.put(USER, System.getenv("DB_USER"));
+ settings.put(PASS, System.getenv("DB_PASSWORD"));
+ settings.put("hibernate.hikari.connectionTimeout", "20000");
+ settings.put("hibernate.hikari.minimumIdle", "1");
+ settings.put("hibernate.hikari.maximumPoolSize", "2");
+ settings.put("hibernate.hikari.idleTimeout", "30000");
+
+// commented out as we only need them on first use
+// settings.put(HBM2DDL_AUTO, "create-only");
+// settings.put(HBM2DDL_DATABASE_ACTION, "create");
+
+ StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
+ .applySettings(settings)
+ .build();
+
+ return new MetadataSources(registry)
+ .addAnnotatedClass(Consignment.class)
+ .addAnnotatedClass(Item.class)
+ .addAnnotatedClass(Checkin.class)
+ .buildMetadata()
+ .buildSessionFactory();
+ }
+}
diff --git a/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Checkin.java b/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Checkin.java
new file mode 100644
index 0000000000..93e6404749
--- /dev/null
+++ b/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Checkin.java
@@ -0,0 +1,28 @@
+package com.baeldung.lambda.shipping;
+
+import javax.persistence.Column;
+import javax.persistence.Embeddable;
+
+@Embeddable
+public class Checkin {
+ private String timeStamp;
+ private String location;
+
+ @Column(name = "timestamp")
+ public String getTimeStamp() {
+ return timeStamp;
+ }
+
+ public void setTimeStamp(String timeStamp) {
+ this.timeStamp = timeStamp;
+ }
+
+ @Column(name = "location")
+ public String getLocation() {
+ return location;
+ }
+
+ public void setLocation(String location) {
+ this.location = location;
+ }
+}
diff --git a/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Consignment.java b/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Consignment.java
new file mode 100644
index 0000000000..1a2371b37f
--- /dev/null
+++ b/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Consignment.java
@@ -0,0 +1,77 @@
+package com.baeldung.lambda.shipping;
+
+import javax.persistence.*;
+import java.util.ArrayList;
+import java.util.List;
+
+import static javax.persistence.FetchType.EAGER;
+
+@Entity(name = "consignment")
+@Table(name = "consignment")
+public class Consignment {
+ private String id;
+ private String source;
+ private String destination;
+ private boolean isDelivered;
+ private List- items = new ArrayList<>();
+ private List checkins = new ArrayList<>();
+
+ @Id
+ @Column(name = "consignment_id")
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ @Column(name = "source")
+ public String getSource() {
+ return source;
+ }
+
+ public void setSource(String source) {
+ this.source = source;
+ }
+
+ @Column(name = "destination")
+ public String getDestination() {
+ return destination;
+ }
+
+ public void setDestination(String destination) {
+ this.destination = destination;
+ }
+
+ @Column(name = "delivered", columnDefinition = "boolean")
+ public boolean isDelivered() {
+ return isDelivered;
+ }
+
+ public void setDelivered(boolean delivered) {
+ isDelivered = delivered;
+ }
+
+ @ElementCollection(fetch = EAGER)
+ @CollectionTable(name = "consignment_item", joinColumns = @JoinColumn(name = "consignment_id"))
+ @OrderColumn(name = "item_index")
+ public List
- getItems() {
+ return items;
+ }
+
+ public void setItems(List
- items) {
+ this.items = items;
+ }
+
+ @ElementCollection(fetch = EAGER)
+ @CollectionTable(name = "consignment_checkin", joinColumns = @JoinColumn(name = "consignment_id"))
+ @OrderColumn(name = "checkin_index")
+ public List getCheckins() {
+ return checkins;
+ }
+
+ public void setCheckins(List checkins) {
+ this.checkins = checkins;
+ }
+}
diff --git a/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Item.java b/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Item.java
new file mode 100644
index 0000000000..de6194e180
--- /dev/null
+++ b/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Item.java
@@ -0,0 +1,38 @@
+package com.baeldung.lambda.shipping;
+
+import javax.persistence.Column;
+import javax.persistence.Embeddable;
+
+@Embeddable
+public class Item {
+ private String location;
+ private String description;
+ private String timeStamp;
+
+ @Column(name = "location")
+ public String getLocation() {
+ return location;
+ }
+
+ public void setLocation(String location) {
+ this.location = location;
+ }
+
+ @Column(name = "description")
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ @Column(name = "timestamp")
+ public String getTimeStamp() {
+ return timeStamp;
+ }
+
+ public void setTimeStamp(String timeStamp) {
+ this.timeStamp = timeStamp;
+ }
+}
diff --git a/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/ShippingDao.java b/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/ShippingDao.java
new file mode 100644
index 0000000000..369dc33935
--- /dev/null
+++ b/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/ShippingDao.java
@@ -0,0 +1,25 @@
+package com.baeldung.lambda.shipping;
+
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+
+import java.util.Optional;
+
+public class ShippingDao {
+ /**
+ * Save a consignment to the database
+ * @param consignment the consignment to save
+ */
+ public void save(Session session, Consignment consignment) {
+ Transaction transaction = session.beginTransaction();
+ session.save(consignment);
+ transaction.commit();
+ }
+
+ /**
+ * Find a consignment in the database by id
+ */
+ public Optional find(Session session, String id) {
+ return Optional.ofNullable(session.get(Consignment.class, id));
+ }
+}
diff --git a/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/ShippingService.java b/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/ShippingService.java
new file mode 100644
index 0000000000..4c951068ea
--- /dev/null
+++ b/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/ShippingService.java
@@ -0,0 +1,62 @@
+package com.baeldung.lambda.shipping;
+
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+
+import java.util.Comparator;
+import java.util.UUID;
+
+public class ShippingService {
+ private SessionFactory sessionFactory;
+ private ShippingDao shippingDao;
+
+ public ShippingService(SessionFactory sessionFactory, ShippingDao shippingDao) {
+ this.sessionFactory = sessionFactory;
+ this.shippingDao = shippingDao;
+ }
+
+ public String createConsignment(Consignment consignment) {
+ try (Session session = sessionFactory.openSession()) {
+ consignment.setDelivered(false);
+ consignment.setId(UUID.randomUUID().toString());
+ shippingDao.save(session, consignment);
+ return consignment.getId();
+ }
+ }
+
+ public void addItem(String consignmentId, Item item) {
+ try (Session session = sessionFactory.openSession()) {
+ shippingDao.find(session, consignmentId)
+ .ifPresent(consignment -> addItem(session, consignment, item));
+ }
+ }
+
+ private void addItem(Session session, Consignment consignment, Item item) {
+ consignment.getItems()
+ .add(item);
+ shippingDao.save(session, consignment);
+ }
+
+ public void checkIn(String consignmentId, Checkin checkin) {
+ try (Session session = sessionFactory.openSession()) {
+ shippingDao.find(session, consignmentId)
+ .ifPresent(consignment -> checkIn(session, consignment, checkin));
+ }
+ }
+
+ private void checkIn(Session session, Consignment consignment, Checkin checkin) {
+ consignment.getCheckins().add(checkin);
+ consignment.getCheckins().sort(Comparator.comparing(Checkin::getTimeStamp));
+ if (checkin.getLocation().equals(consignment.getDestination())) {
+ consignment.setDelivered(true);
+ }
+ shippingDao.save(session, consignment);
+ }
+
+ public Consignment view(String consignmentId) {
+ try (Session session = sessionFactory.openSession()) {
+ return shippingDao.find(session, consignmentId)
+ .orElseGet(Consignment::new);
+ }
+ }
+}
diff --git a/aws-lambda/shipping-tracker/template.yaml b/aws-lambda/shipping-tracker/template.yaml
new file mode 100644
index 0000000000..ec75c51ba1
--- /dev/null
+++ b/aws-lambda/shipping-tracker/template.yaml
@@ -0,0 +1,47 @@
+AWSTemplateFormatVersion: '2010-09-09'
+Transform: AWS::Serverless-2016-10-31
+Description: >
+ shipping-tracker
+
+ Sample SAM Template for shipping-tracker
+
+# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
+Globals:
+ Function:
+ Timeout: 20
+
+Resources:
+ ShippingFunction:
+ Type: AWS::Serverless::Function
+ Properties:
+ CodeUri: ShippingFunction
+ Handler: com.baeldung.lambda.shipping.App::handleRequest
+ Runtime: java8
+ MemorySize: 512
+ Environment:
+ Variables:
+ DB_URL: jdbc:postgresql://postgres/postgres
+ DB_USER: postgres
+ DB_PASSWORD: password
+ Events:
+ CreateConsignment:
+ Type: Api
+ Properties:
+ Path: /consignment
+ Method: post
+ AddItem:
+ Type: Api
+ Properties:
+ Path: /consignment/{id}/item
+ Method: post
+ CheckIn:
+ Type: Api
+ Properties:
+ Path: /consignment/{id}/checkin
+ Method: post
+ ViewConsignment:
+ Type: Api
+ Properties:
+ Path: /consignment/{id}
+ Method: get
+
diff --git a/core-java-modules/core-java-11-2/README.md b/core-java-modules/core-java-11-2/README.md
index f65a043819..834f310fce 100644
--- a/core-java-modules/core-java-11-2/README.md
+++ b/core-java-modules/core-java-11-2/README.md
@@ -4,4 +4,5 @@ This module contains articles about Java 11 core features
### Relevant articles
- [Guide to Java 8 Optional](https://www.baeldung.com/java-optional)
-
+- [Guide to Java Reflection](http://www.baeldung.com/java-reflection)
+- [Guide to Java 8’s Collectors](https://www.baeldung.com/java-8-collectors)
diff --git a/core-java-modules/core-java-11-2/pom.xml b/core-java-modules/core-java-11-2/pom.xml
index d20b0f23f0..e2b129ae00 100644
--- a/core-java-modules/core-java-11-2/pom.xml
+++ b/core-java-modules/core-java-11-2/pom.xml
@@ -17,6 +17,11 @@
+
+ com.google.guava
+ guava
+ ${guava.version}
+
org.assertj
assertj-core
@@ -42,6 +47,7 @@
11
11
+ 29.0-jre
3.17.2
diff --git a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Animal.java b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Animal.java
similarity index 90%
rename from core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Animal.java
rename to core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Animal.java
index 3f36243c29..364246ae64 100644
--- a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Animal.java
+++ b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Animal.java
@@ -1,4 +1,4 @@
-package com.baeldung.java.reflection;
+package com.baeldung.reflection;
public abstract class Animal implements Eating {
diff --git a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Bird.java b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Bird.java
similarity index 93%
rename from core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Bird.java
rename to core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Bird.java
index bd6f13094c..f5bb0f9b19 100644
--- a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Bird.java
+++ b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Bird.java
@@ -1,4 +1,4 @@
-package com.baeldung.java.reflection;
+package com.baeldung.reflection;
public class Bird extends Animal {
private boolean walks;
diff --git a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/DynamicGreeter.java b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/DynamicGreeter.java
similarity index 91%
rename from core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/DynamicGreeter.java
rename to core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/DynamicGreeter.java
index 3776ef82e2..b7ff083daf 100644
--- a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/DynamicGreeter.java
+++ b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/DynamicGreeter.java
@@ -1,4 +1,4 @@
-package com.baeldung.java.reflection;
+package com.baeldung.reflection;
import java.lang.annotation.Annotation;
diff --git a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Eating.java b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Eating.java
similarity index 55%
rename from core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Eating.java
rename to core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Eating.java
index 479425cad4..c959becf00 100644
--- a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Eating.java
+++ b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Eating.java
@@ -1,4 +1,4 @@
-package com.baeldung.java.reflection;
+package com.baeldung.reflection;
public interface Eating {
String eats();
diff --git a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Goat.java b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Goat.java
similarity index 90%
rename from core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Goat.java
rename to core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Goat.java
index 503717ae5e..086d09d543 100644
--- a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Goat.java
+++ b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Goat.java
@@ -1,4 +1,4 @@
-package com.baeldung.java.reflection;
+package com.baeldung.reflection;
public class Goat extends Animal implements Locomotion {
diff --git a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Greeter.java b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Greeter.java
similarity index 83%
rename from core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Greeter.java
rename to core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Greeter.java
index 57aefdd169..d06a719312 100644
--- a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Greeter.java
+++ b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Greeter.java
@@ -1,4 +1,4 @@
-package com.baeldung.java.reflection;
+package com.baeldung.reflection;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
diff --git a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/GreetingAnnotation.java b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/GreetingAnnotation.java
similarity index 98%
rename from core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/GreetingAnnotation.java
rename to core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/GreetingAnnotation.java
index 601306f5d2..f23c407c52 100644
--- a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/GreetingAnnotation.java
+++ b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/GreetingAnnotation.java
@@ -1,4 +1,4 @@
-package com.baeldung.java.reflection;
+package com.baeldung.reflection;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
diff --git a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Greetings.java b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Greetings.java
similarity index 61%
rename from core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Greetings.java
rename to core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Greetings.java
index 4f3a20c3b9..fc6dfe949b 100644
--- a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Greetings.java
+++ b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Greetings.java
@@ -1,4 +1,4 @@
-package com.baeldung.java.reflection;
+package com.baeldung.reflection;
@Greeter(greet="Good morning")
public class Greetings {
diff --git a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Locomotion.java b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Locomotion.java
similarity index 61%
rename from core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Locomotion.java
rename to core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Locomotion.java
index 047c00cb13..230fd9a466 100644
--- a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Locomotion.java
+++ b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Locomotion.java
@@ -1,4 +1,4 @@
-package com.baeldung.java.reflection;
+package com.baeldung.reflection;
public interface Locomotion {
String getLocomotion();
diff --git a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Operations.java b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Operations.java
similarity index 90%
rename from core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Operations.java
rename to core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Operations.java
index da4b479b02..5264378524 100644
--- a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Operations.java
+++ b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Operations.java
@@ -1,4 +1,4 @@
-package com.baeldung.java.reflection;
+package com.baeldung.reflection;
public class Operations {
diff --git a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Person.java b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Person.java
similarity index 65%
rename from core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Person.java
rename to core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Person.java
index f3d7f9f001..1a1fafef93 100644
--- a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Person.java
+++ b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Person.java
@@ -1,4 +1,4 @@
-package com.baeldung.java.reflection;
+package com.baeldung.reflection;
public class Person {
private String name;
diff --git a/core-java-modules/core-java-streams-3/src/test/java/com/baeldung/streams/collectors/Java8CollectorsUnitTest.java b/core-java-modules/core-java-11-2/src/test/java/com/baeldung/collectors/Java8CollectorsUnitTest.java
similarity index 87%
rename from core-java-modules/core-java-streams-3/src/test/java/com/baeldung/streams/collectors/Java8CollectorsUnitTest.java
rename to core-java-modules/core-java-11-2/src/test/java/com/baeldung/collectors/Java8CollectorsUnitTest.java
index 6afc9f4182..7990b1fdb7 100644
--- a/core-java-modules/core-java-streams-3/src/test/java/com/baeldung/streams/collectors/Java8CollectorsUnitTest.java
+++ b/core-java-modules/core-java-11-2/src/test/java/com/baeldung/collectors/Java8CollectorsUnitTest.java
@@ -1,18 +1,11 @@
-package com.baeldung.streams.collectors;
+package com.baeldung.collectors;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import org.junit.Test;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.DoubleSummaryStatistics;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
+import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.BinaryOperator;
import java.util.function.Function;
@@ -20,19 +13,7 @@ import java.util.function.Supplier;
import java.util.stream.Collector;
import static com.google.common.collect.Sets.newHashSet;
-import static java.util.stream.Collectors.averagingDouble;
-import static java.util.stream.Collectors.collectingAndThen;
-import static java.util.stream.Collectors.counting;
-import static java.util.stream.Collectors.groupingBy;
-import static java.util.stream.Collectors.joining;
-import static java.util.stream.Collectors.maxBy;
-import static java.util.stream.Collectors.partitioningBy;
-import static java.util.stream.Collectors.summarizingDouble;
-import static java.util.stream.Collectors.summingDouble;
-import static java.util.stream.Collectors.toCollection;
-import static java.util.stream.Collectors.toList;
-import static java.util.stream.Collectors.toMap;
-import static java.util.stream.Collectors.toSet;
+import static java.util.stream.Collectors.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -48,6 +29,14 @@ public class Java8CollectorsUnitTest {
assertThat(result).containsAll(givenList);
}
+ @Test
+ public void whenCollectingToUnmodifiableList_shouldCollectToUnmodifiableList() {
+ final List result = givenList.stream().collect(toUnmodifiableList());
+
+ assertThatThrownBy(() -> result.add("foo"))
+ .isInstanceOf(UnsupportedOperationException.class);
+ }
+
@Test
public void whenCollectingToSet_shouldCollectToSet() throws Exception {
final Set result = givenList.stream().collect(toSet());
@@ -55,6 +44,14 @@ public class Java8CollectorsUnitTest {
assertThat(result).containsAll(givenList);
}
+ @Test
+ public void whenCollectingToUnmodifiableSet_shouldCollectToUnmodifiableSet() {
+ final Set result = givenList.stream().collect(toUnmodifiableSet());
+
+ assertThatThrownBy(() -> result.add("foo"))
+ .isInstanceOf(UnsupportedOperationException.class);
+ }
+
@Test
public void givenContainsDuplicateElements_whenCollectingToSet_shouldAddDuplicateElementsOnlyOnce() throws Exception {
final Set result = listWithDuplicates.stream().collect(toSet());
@@ -84,6 +81,15 @@ public class Java8CollectorsUnitTest {
assertThat(result).containsEntry("a", 1).containsEntry("bb", 2).containsEntry("ccc", 3).containsEntry("dd", 2);
}
+ @Test
+ public void whenCollectingToUnmodifiableMap_shouldCollectToUnmodifiableMap() {
+ final Map result = givenList.stream()
+ .collect(toUnmodifiableMap(Function.identity(), String::length));
+
+ assertThatThrownBy(() -> result.put("foo", 3))
+ .isInstanceOf(UnsupportedOperationException.class);
+ }
+
@Test
public void whenCollectingToMapwWithDuplicates_shouldCollectToMapMergingTheIdenticalItems() throws Exception {
final Map result = listWithDuplicates.stream().collect(
diff --git a/core-java-modules/core-java-reflection/src/test/java/com/baeldung/reflection/java/reflection/OperationsUnitTest.java b/core-java-modules/core-java-11-2/src/test/java/com/baeldung/reflection/OperationsUnitTest.java
similarity index 98%
rename from core-java-modules/core-java-reflection/src/test/java/com/baeldung/reflection/java/reflection/OperationsUnitTest.java
rename to core-java-modules/core-java-11-2/src/test/java/com/baeldung/reflection/OperationsUnitTest.java
index 217910bffd..7584d5da94 100644
--- a/core-java-modules/core-java-reflection/src/test/java/com/baeldung/reflection/java/reflection/OperationsUnitTest.java
+++ b/core-java-modules/core-java-11-2/src/test/java/com/baeldung/reflection/OperationsUnitTest.java
@@ -1,4 +1,4 @@
-package com.baeldung.java.reflection;
+package com.baeldung.reflection;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertFalse;
diff --git a/core-java-modules/core-java-reflection/src/test/java/com/baeldung/reflection/java/reflection/ReflectionUnitTest.java b/core-java-modules/core-java-11-2/src/test/java/com/baeldung/reflection/ReflectionUnitTest.java
similarity index 77%
rename from core-java-modules/core-java-reflection/src/test/java/com/baeldung/reflection/java/reflection/ReflectionUnitTest.java
rename to core-java-modules/core-java-11-2/src/test/java/com/baeldung/reflection/ReflectionUnitTest.java
index a791d64874..c73fa5f8e0 100644
--- a/core-java-modules/core-java-reflection/src/test/java/com/baeldung/reflection/java/reflection/ReflectionUnitTest.java
+++ b/core-java-modules/core-java-11-2/src/test/java/com/baeldung/reflection/ReflectionUnitTest.java
@@ -1,4 +1,4 @@
-package com.baeldung.java.reflection;
+package com.baeldung.reflection;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -32,23 +32,23 @@ public class ReflectionUnitTest {
final Class> clazz = goat.getClass();
assertEquals("Goat", clazz.getSimpleName());
- assertEquals("com.baeldung.java.reflection.Goat", clazz.getName());
- assertEquals("com.baeldung.java.reflection.Goat", clazz.getCanonicalName());
+ assertEquals("com.baeldung.reflection.Goat", clazz.getName());
+ assertEquals("com.baeldung.reflection.Goat", clazz.getCanonicalName());
}
@Test
public void givenClassName_whenCreatesObject_thenCorrect() throws ClassNotFoundException {
- final Class> clazz = Class.forName("com.baeldung.java.reflection.Goat");
+ final Class> clazz = Class.forName("com.baeldung.reflection.Goat");
assertEquals("Goat", clazz.getSimpleName());
- assertEquals("com.baeldung.java.reflection.Goat", clazz.getName());
- assertEquals("com.baeldung.java.reflection.Goat", clazz.getCanonicalName());
+ assertEquals("com.baeldung.reflection.Goat", clazz.getName());
+ assertEquals("com.baeldung.reflection.Goat", clazz.getCanonicalName());
}
@Test
public void givenClass_whenRecognisesModifiers_thenCorrect() throws ClassNotFoundException {
- final Class> goatClass = Class.forName("com.baeldung.java.reflection.Goat");
- final Class> animalClass = Class.forName("com.baeldung.java.reflection.Animal");
+ final Class> goatClass = Class.forName("com.baeldung.reflection.Goat");
+ final Class> animalClass = Class.forName("com.baeldung.reflection.Animal");
final int goatMods = goatClass.getModifiers();
final int animalMods = animalClass.getModifiers();
@@ -63,7 +63,7 @@ public class ReflectionUnitTest {
final Class> goatClass = goat.getClass();
final Package pkg = goatClass.getPackage();
- assertEquals("com.baeldung.java.reflection", pkg.getName());
+ assertEquals("com.baeldung.reflection", pkg.getName());
}
@Test
@@ -81,8 +81,8 @@ public class ReflectionUnitTest {
@Test
public void givenClass_whenGetsImplementedInterfaces_thenCorrect() throws ClassNotFoundException {
- final Class> goatClass = Class.forName("com.baeldung.java.reflection.Goat");
- final Class> animalClass = Class.forName("com.baeldung.java.reflection.Animal");
+ final Class> goatClass = Class.forName("com.baeldung.reflection.Goat");
+ final Class> animalClass = Class.forName("com.baeldung.reflection.Animal");
final Class>[] goatInterfaces = goatClass.getInterfaces();
final Class>[] animalInterfaces = animalClass.getInterfaces();
@@ -94,16 +94,16 @@ public class ReflectionUnitTest {
@Test
public void givenClass_whenGetsConstructor_thenCorrect() throws ClassNotFoundException {
- final Class> goatClass = Class.forName("com.baeldung.java.reflection.Goat");
+ final Class> goatClass = Class.forName("com.baeldung.reflection.Goat");
final Constructor>[] constructors = goatClass.getConstructors();
assertEquals(1, constructors.length);
- assertEquals("com.baeldung.java.reflection.Goat", constructors[0].getName());
+ assertEquals("com.baeldung.reflection.Goat", constructors[0].getName());
}
@Test
public void givenClass_whenGetsFields_thenCorrect() throws ClassNotFoundException {
- final Class> animalClass = Class.forName("com.baeldung.java.reflection.Animal");
+ final Class> animalClass = Class.forName("com.baeldung.reflection.Animal");
final Field[] fields = animalClass.getDeclaredFields();
final List actualFields = getFieldNames(fields);
@@ -114,7 +114,7 @@ public class ReflectionUnitTest {
@Test
public void givenClass_whenGetsMethods_thenCorrect() throws ClassNotFoundException {
- final Class> animalClass = Class.forName("com.baeldung.java.reflection.Animal");
+ final Class> animalClass = Class.forName("com.baeldung.reflection.Animal");
final Method[] methods = animalClass.getDeclaredMethods();
final List actualMethods = getMethodNames(methods);
@@ -124,7 +124,7 @@ public class ReflectionUnitTest {
@Test
public void givenClass_whenGetsAllConstructors_thenCorrect() throws ClassNotFoundException {
- final Class> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
+ final Class> birdClass = Class.forName("com.baeldung.reflection.Bird");
final Constructor>[] constructors = birdClass.getConstructors();
assertEquals(3, constructors.length);
@@ -132,7 +132,7 @@ public class ReflectionUnitTest {
@Test
public void givenClass_whenGetsEachConstructorByParamTypes_thenCorrect() throws Exception {
- final Class> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
+ final Class> birdClass = Class.forName("com.baeldung.reflection.Bird");
birdClass.getConstructor();
birdClass.getConstructor(String.class);
birdClass.getConstructor(String.class, boolean.class);
@@ -140,7 +140,7 @@ public class ReflectionUnitTest {
@Test
public void givenClass_whenInstantiatesObjectsAtRuntime_thenCorrect() throws Exception {
- final Class> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
+ final Class> birdClass = Class.forName("com.baeldung.reflection.Bird");
final Constructor> cons1 = birdClass.getConstructor();
final Constructor> cons2 = birdClass.getConstructor(String.class);
@@ -159,7 +159,7 @@ public class ReflectionUnitTest {
@Test
public void givenClass_whenGetsPublicFields_thenCorrect() throws ClassNotFoundException {
- final Class> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
+ final Class> birdClass = Class.forName("com.baeldung.reflection.Bird");
final Field[] fields = birdClass.getFields();
assertEquals(1, fields.length);
assertEquals("CATEGORY", fields[0].getName());
@@ -168,7 +168,7 @@ public class ReflectionUnitTest {
@Test
public void givenClass_whenGetsPublicFieldByName_thenCorrect() throws Exception {
- final Class> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
+ final Class> birdClass = Class.forName("com.baeldung.reflection.Bird");
final Field field = birdClass.getField("CATEGORY");
assertEquals("CATEGORY", field.getName());
@@ -176,7 +176,7 @@ public class ReflectionUnitTest {
@Test
public void givenClass_whenGetsDeclaredFields_thenCorrect() throws ClassNotFoundException {
- final Class> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
+ final Class> birdClass = Class.forName("com.baeldung.reflection.Bird");
final Field[] fields = birdClass.getDeclaredFields();
assertEquals(1, fields.length);
assertEquals("walks", fields[0].getName());
@@ -184,7 +184,7 @@ public class ReflectionUnitTest {
@Test
public void givenClass_whenGetsFieldsByName_thenCorrect() throws Exception {
- final Class> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
+ final Class> birdClass = Class.forName("com.baeldung.reflection.Bird");
final Field field = birdClass.getDeclaredField("walks");
assertEquals("walks", field.getName());
@@ -192,14 +192,14 @@ public class ReflectionUnitTest {
@Test
public void givenClassField_whenGetsType_thenCorrect() throws Exception {
- final Field field = Class.forName("com.baeldung.java.reflection.Bird").getDeclaredField("walks");
+ final Field field = Class.forName("com.baeldung.reflection.Bird").getDeclaredField("walks");
final Class> fieldClass = field.getType();
assertEquals("boolean", fieldClass.getSimpleName());
}
@Test
public void givenClassField_whenSetsAndGetsValue_thenCorrect() throws Exception {
- final Class> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
+ final Class> birdClass = Class.forName("com.baeldung.reflection.Bird");
final Bird bird = (Bird) birdClass.getConstructor().newInstance();
final Field field = birdClass.getDeclaredField("walks");
field.setAccessible(true);
@@ -216,7 +216,7 @@ public class ReflectionUnitTest {
@Test
public void givenClassField_whenGetsAndSetsWithNull_thenCorrect() throws Exception {
- final Class> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
+ final Class> birdClass = Class.forName("com.baeldung.reflection.Bird");
final Field field = birdClass.getField("CATEGORY");
field.setAccessible(true);
@@ -225,7 +225,7 @@ public class ReflectionUnitTest {
@Test
public void givenClass_whenGetsAllPublicMethods_thenCorrect() throws ClassNotFoundException {
- final Class> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
+ final Class> birdClass = Class.forName("com.baeldung.reflection.Bird");
final Method[] methods = birdClass.getMethods();
final List methodNames = getMethodNames(methods);
@@ -235,7 +235,7 @@ public class ReflectionUnitTest {
@Test
public void givenClass_whenGetsOnlyDeclaredMethods_thenCorrect() throws ClassNotFoundException {
- final Class> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
+ final Class> birdClass = Class.forName("com.baeldung.reflection.Bird");
final List actualMethodNames = getMethodNames(birdClass.getDeclaredMethods());
final List expectedMethodNames = Arrays.asList("setWalks", "walks", "getSound", "eats");
@@ -248,24 +248,17 @@ public class ReflectionUnitTest {
@Test
public void givenMethodName_whenGetsMethod_thenCorrect() throws Exception {
- final Class> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
- final Method walksMethod = birdClass.getDeclaredMethod("walks");
- final Method setWalksMethod = birdClass.getDeclaredMethod("setWalks", boolean.class);
-
- assertFalse(walksMethod.isAccessible());
- assertFalse(setWalksMethod.isAccessible());
-
- walksMethod.setAccessible(true);
- setWalksMethod.setAccessible(true);
-
- assertTrue(walksMethod.isAccessible());
- assertTrue(setWalksMethod.isAccessible());
+ final Bird bird = new Bird();
+ final Method walksMethod = bird.getClass().getDeclaredMethod("walks");
+ final Method setWalksMethod = bird.getClass().getDeclaredMethod("setWalks", boolean.class);
+ assertTrue(walksMethod.canAccess(bird));
+ assertTrue(setWalksMethod.canAccess(bird));
}
@Test
public void givenMethod_whenInvokes_thenCorrect() throws Exception {
- final Class> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
+ final Class> birdClass = Class.forName("com.baeldung.reflection.Bird");
final Bird bird = (Bird) birdClass.getConstructor().newInstance();
final Method setWalksMethod = birdClass.getDeclaredMethod("setWalks", boolean.class);
final Method walksMethod = birdClass.getDeclaredMethod("walks");
diff --git a/core-java-modules/core-java-collections-3/src/test/java/com/baeldung/collections/mapfirstpair/MapFirstPairUnitTest.java b/core-java-modules/core-java-collections-3/src/test/java/com/baeldung/collections/mapfirstpair/MapFirstPairUnitTest.java
new file mode 100644
index 0000000000..b25e0932d8
--- /dev/null
+++ b/core-java-modules/core-java-collections-3/src/test/java/com/baeldung/collections/mapfirstpair/MapFirstPairUnitTest.java
@@ -0,0 +1,143 @@
+package com.baeldung.collections.mapfirstpair;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+
+import java.util.AbstractMap;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.junit.Test;
+
+public class MapFirstPairUnitTest {
+
+ private Map.Entry getFirstPairUsingIterator(Map map) {
+ if (map == null || map.size() == 0)
+ return null;
+
+ Iterator> iterator = map.entrySet()
+ .iterator();
+
+ if (iterator.hasNext())
+ return iterator.next();
+
+ return null;
+ }
+
+ private Map.Entry getFirstPairUsingStream(Map map) {
+ if (map == null || map.size() == 0)
+ return null;
+
+ Set> entrySet = map.entrySet();
+
+ return entrySet.stream()
+ .findFirst()
+ .get();
+ }
+
+ private Map populateMapValues(Map map) {
+ if (map != null) {
+ map.put(5, "A");
+ map.put(1, "B");
+ map.put(2, "C");
+ }
+ return map;
+ }
+
+ @Test
+ public void whenUsingIteratorForHashMap_thenFirstPairWhichWasNotInsertedFirst() {
+ Map hashMap = new HashMap<>();
+ hashMap = populateMapValues(hashMap);
+
+ Map.Entry actualValue = getFirstPairUsingIterator(hashMap);
+ Map.Entry expectedValue = new AbstractMap.SimpleEntry(1, "B");
+ Map.Entry pairInsertedFirst = new AbstractMap.SimpleEntry(5, "A");
+
+ assertEquals(expectedValue, actualValue);
+ assertNotEquals(pairInsertedFirst, actualValue);
+ }
+
+ @Test
+ public void whenUsingStreamForHashMap_thenFirstPairWhichWasNotInsertedFirst() {
+ Map hashMap = new HashMap<>();
+ hashMap = populateMapValues(hashMap);
+ Map.Entry actualValue = getFirstPairUsingStream(hashMap);
+ Map.Entry expectedValue = new AbstractMap.SimpleEntry(1, "B");
+ Map.Entry pairInsertedFirst = new AbstractMap.SimpleEntry(5, "A");
+
+ assertEquals(expectedValue, actualValue);
+ assertNotEquals(pairInsertedFirst, actualValue);
+ }
+
+ @Test
+ public void whenUsingIteratorForLinkedHashMap_thenFirstPairWhichWasInsertedFirst() {
+ Map linkedHashMap = new LinkedHashMap<>();
+ linkedHashMap = populateMapValues(linkedHashMap);
+ Map.Entry actualValue = getFirstPairUsingIterator(linkedHashMap);
+ Map.Entry expectedValue = new AbstractMap.SimpleEntry(5, "A");
+
+ assertEquals(expectedValue, actualValue);
+ }
+
+ @Test
+ public void whenUsingStreamForLinkedHashMap_thenFirstPairWhichWasInsertedFirst() {
+ Map linkedHashMap = new LinkedHashMap<>();
+ linkedHashMap = populateMapValues(linkedHashMap);
+
+ Map.Entry actualValue = getFirstPairUsingStream(linkedHashMap);
+ Map.Entry expectedValue = new AbstractMap.SimpleEntry(5, "A");
+
+ assertEquals(expectedValue, actualValue);
+ }
+
+ @Test
+ public void whenAddedAnElementInHashMap_thenFirstPairChangedUsingIterator() {
+ Map hashMap = new HashMap<>();
+ hashMap = populateMapValues(hashMap);
+
+ hashMap.put(0, "D");
+ Map.Entry actualValue = getFirstPairUsingIterator(hashMap);
+ Map.Entry expectedValue = new AbstractMap.SimpleEntry(0, "D");
+
+ assertEquals(expectedValue, actualValue);
+ }
+
+ @Test
+ public void whenAddedAnElementInHashMap_thenFirstPairChangedUsingStream() {
+ Map hashMap = new HashMap<>();
+ hashMap = populateMapValues(hashMap);
+
+ hashMap.put(0, "D");
+ Map.Entry actualValue = getFirstPairUsingStream(hashMap);
+ Map.Entry expectedValue = new AbstractMap.SimpleEntry(0, "D");
+
+ assertEquals(expectedValue, actualValue);
+ }
+
+ @Test
+ public void whenAddedAnElementInLinkedHashMap_thenFirstPairRemainUnchangedUsingIterator() {
+ Map linkedHashMap = new LinkedHashMap<>();
+ linkedHashMap = populateMapValues(linkedHashMap);
+
+ linkedHashMap.put(0, "D");
+ Map.Entry actualValue = getFirstPairUsingIterator(linkedHashMap);
+ Map.Entry expectedValue = new AbstractMap.SimpleEntry(5, "A");
+
+ assertEquals(expectedValue, actualValue);
+ }
+
+ @Test
+ public void whenAddedAnElementInLinkedHashMap_thenFirstPairRemainUnchangedUsingStream() {
+ Map linkedHashMap = new LinkedHashMap<>();
+ linkedHashMap = populateMapValues(linkedHashMap);
+
+ linkedHashMap.put(0, "D");
+ Map.Entry actualValue = getFirstPairUsingStream(linkedHashMap);
+ Map.Entry expectedValue = new AbstractMap.SimpleEntry(5, "A");
+
+ assertEquals(expectedValue, actualValue);
+ }
+}
diff --git a/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/checkclassexistence/CheckClassExistenceUnitTest.java b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/checkclassexistence/CheckClassExistenceUnitTest.java
new file mode 100644
index 0000000000..b565f9de31
--- /dev/null
+++ b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/checkclassexistence/CheckClassExistenceUnitTest.java
@@ -0,0 +1,34 @@
+package com.baeldung.checkclassexistence;
+
+import org.junit.Test;
+
+public class CheckClassExistenceUnitTest {
+
+ public static class InitializingClass {
+ static {
+ if (true) { //enable throwing of an exception in a static initialization block
+ throw new RuntimeException();
+ }
+ }
+ }
+
+ @Test(expected = ClassNotFoundException.class) //thrown when class does not exist
+ public void givenNonExistingClass_whenUsingForName_thenClassNotFound() throws ClassNotFoundException {
+ Class.forName("class.that.does.not.exist");
+ }
+
+ @Test
+ public void givenExistingClass_whenUsingForName_thenNoException() throws ClassNotFoundException {
+ Class.forName("java.lang.String");
+ }
+
+ @Test(expected = ExceptionInInitializerError.class) //thrown when exception occurs inside of a static initialization block
+ public void givenInitializingClass_whenUsingForName_thenInitializationError() throws ClassNotFoundException {
+ Class.forName("com.baeldung.checkclassexistence.CheckClassExistenceUnitTest$InitializingClass");
+ }
+
+ @Test
+ public void givenInitializingClass_whenUsingForNameWithoutInitialization_thenNoException() throws ClassNotFoundException {
+ Class.forName("com.baeldung.checkclassexistence.CheckClassExistenceUnitTest$InitializingClass", false, getClass().getClassLoader());
+ }
+}
diff --git a/core-java-modules/core-java-networking-2/pom.xml b/core-java-modules/core-java-networking-2/pom.xml
index d79320eaef..89a98bbf8b 100644
--- a/core-java-modules/core-java-networking-2/pom.xml
+++ b/core-java-modules/core-java-networking-2/pom.xml
@@ -35,6 +35,12 @@
async-http-client
${async-http-client.version}
+
+ com.icegreen
+ greenmail
+ 1.5.8
+ test
+
diff --git a/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/mail/mailwithattachment/MailWithAttachmentService.java b/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/mail/mailwithattachment/MailWithAttachmentService.java
new file mode 100644
index 0000000000..7d4dc57f10
--- /dev/null
+++ b/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/mail/mailwithattachment/MailWithAttachmentService.java
@@ -0,0 +1,83 @@
+package com.baeldung.mail.mailwithattachment;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Properties;
+import javax.mail.BodyPart;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.Multipart;
+import javax.mail.PasswordAuthentication;
+import javax.mail.Session;
+import javax.mail.Transport;
+import javax.mail.internet.AddressException;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeBodyPart;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMultipart;
+
+public class MailWithAttachmentService {
+
+ private String username = "";
+ private String password = "";
+ private String host = "";
+ private String port = "";
+
+ MailWithAttachmentService() {
+ }
+
+ MailWithAttachmentService(String username, String password, String host, String port) {
+ this.username = username;
+ this.password = password;
+ this.host = host;
+ this.port = port;
+ }
+
+ public Session getSession() {
+ Properties props = new Properties();
+ props.put("mail.smtp.auth", "true");
+ props.put("mail.smtp.starttls.enable", "true");
+ props.put("mail.smtp.host", this.host);
+ props.put("mail.smtp.port", this.port);
+
+ Session session = Session.getInstance(props, new javax.mail.Authenticator() {
+ protected PasswordAuthentication getPasswordAuthentication() {
+ return new PasswordAuthentication(username, password);
+ }
+ });
+ return session;
+ }
+
+ public Message createMail(Session session) throws AddressException, MessagingException, IOException {
+ Message message = new MimeMessage(session);
+ message.setFrom(new InternetAddress("mail@gmail.com"));
+ message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("mail@gmail.com"));
+ message.setSubject("Testing Subject");
+
+ BodyPart messageBodyPart = new MimeBodyPart();
+ messageBodyPart.setText("This is message body");
+
+ Multipart multipart = new MimeMultipart();
+ multipart.addBodyPart(messageBodyPart);
+
+ MimeBodyPart attachmentPart = new MimeBodyPart();
+ MimeBodyPart attachmentPart2 = new MimeBodyPart();
+
+ attachmentPart.attachFile(new File("C:\\Document1.txt"));
+ attachmentPart2.attachFile(new File("C:\\Document2.txt"));
+
+ multipart.addBodyPart(attachmentPart);
+ multipart.addBodyPart(attachmentPart2);
+
+ message.setContent(multipart);
+
+ return message;
+ }
+
+ public void sendMail(Session session) throws MessagingException, IOException {
+
+ Message message = createMail(session);
+ Transport.send(message);
+ }
+
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-networking-2/src/test/java/com/baeldung/mail/mailwithattachment/MailWithAttachmentServiceLiveTest.java b/core-java-modules/core-java-networking-2/src/test/java/com/baeldung/mail/mailwithattachment/MailWithAttachmentServiceLiveTest.java
new file mode 100644
index 0000000000..ef82657ab5
--- /dev/null
+++ b/core-java-modules/core-java-networking-2/src/test/java/com/baeldung/mail/mailwithattachment/MailWithAttachmentServiceLiveTest.java
@@ -0,0 +1,48 @@
+package com.baeldung.mail.mailwithattachment;
+
+import static org.junit.Assert.*;
+import javax.annotation.Resource;
+import javax.mail.Session;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.baeldung.mail.mailwithattachment.MailWithAttachmentService;
+import com.icegreen.greenmail.util.GreenMail;
+import com.icegreen.greenmail.util.ServerSetupTest;
+
+public class MailWithAttachmentServiceLiveTest {
+
+ @Resource
+ private MailWithAttachmentService emailService;
+ private GreenMail greenMail;
+
+ @Before
+ public void startMailServer() {
+ emailService = new MailWithAttachmentService();
+ greenMail = new GreenMail(ServerSetupTest.SMTP);
+ greenMail.start();
+ }
+
+ @After
+ public void stopMailServer() {
+ greenMail.stop();
+ emailService = null;
+ }
+
+ @Test
+ public void canSendMail() {
+ try {
+ Session testSession = greenMail.getSmtp()
+ .createSession();
+ emailService.sendMail(testSession);
+ assertEquals(1, greenMail.getReceivedMessages().length);
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ }
+
+}
diff --git a/core-java-modules/core-java-reflection/README.MD b/core-java-modules/core-java-reflection/README.MD
index 5d8c54414b..62d8719981 100644
--- a/core-java-modules/core-java-reflection/README.MD
+++ b/core-java-modules/core-java-reflection/README.MD
@@ -3,7 +3,6 @@
- [Void Type in Java](https://www.baeldung.com/java-void-type)
- [Retrieve Fields from a Java Class Using Reflection](https://www.baeldung.com/java-reflection-class-fields)
- [Method Parameter Reflection in Java](http://www.baeldung.com/java-parameter-reflection)
-- [Guide to Java Reflection](http://www.baeldung.com/java-reflection)
- [Call Methods at Runtime Using Java Reflection](http://www.baeldung.com/java-method-reflection)
- [Changing Annotation Parameters At Runtime](http://www.baeldung.com/java-reflection-change-annotation-params)
- [Dynamic Proxies in Java](http://www.baeldung.com/java-dynamic-proxies)
diff --git a/core-java-modules/core-java-streams-3/README.md b/core-java-modules/core-java-streams-3/README.md
index 65713aa04f..9adde005e6 100644
--- a/core-java-modules/core-java-streams-3/README.md
+++ b/core-java-modules/core-java-streams-3/README.md
@@ -6,7 +6,6 @@ This module contains articles about the Stream API in Java.
- [The Difference Between map() and flatMap()](https://www.baeldung.com/java-difference-map-and-flatmap)
- [How to Use if/else Logic in Java 8 Streams](https://www.baeldung.com/java-8-streams-if-else-logic)
- [The Difference Between Collection.stream().forEach() and Collection.forEach()](https://www.baeldung.com/java-collection-stream-foreach)
-- [Guide to Java 8’s Collectors](https://www.baeldung.com/java-8-collectors)
- [Primitive Type Streams in Java 8](https://www.baeldung.com/java-8-primitive-streams)
- [Debugging Java 8 Streams with IntelliJ](https://www.baeldung.com/intellij-debugging-java-streams)
- [Add BigDecimals using the Stream API](https://www.baeldung.com/java-stream-add-bigdecimals)
diff --git a/ddd/pom.xml b/ddd/pom.xml
index 9f960502a3..a67719f8a6 100644
--- a/ddd/pom.xml
+++ b/ddd/pom.xml
@@ -78,6 +78,10 @@
org.springframework.boot
spring-boot-starter-web
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
org.springframework.boot
spring-boot-starter-test
diff --git a/gradle-5/cmd-line-args/build.gradle b/gradle-5/cmd-line-args/build.gradle
new file mode 100644
index 0000000000..15c9288024
--- /dev/null
+++ b/gradle-5/cmd-line-args/build.gradle
@@ -0,0 +1,38 @@
+apply plugin: "java"
+apply plugin: "application"
+description = "Gradle Command Line Arguments examples"
+
+ext.javaMainClass = "com.baeldung.cmd.MainClass"
+
+application {
+ mainClassName = javaMainClass
+}
+
+task propertyTypes(){
+ doLast{
+ if (project.hasProperty("args")) {
+ println "Our input argument with project property ["+project.getProperty("args")+"]"
+ }
+ println "Our input argument with system property ["+System.getProperty("args")+"]"
+ }
+}
+
+if (project.hasProperty("args")) {
+ ext.cmdargs = project.getProperty("args")
+} else {
+ ext.cmdargs = "ls"
+}
+
+task cmdLineJavaExec(type: JavaExec) {
+ group = "Execution"
+ description = "Run the main class with JavaExecTask"
+ classpath = sourceSets.main.runtimeClasspath
+ main = javaMainClass
+ args cmdargs.split()
+}
+
+task cmdLineExec(type: Exec) {
+ group = "Execution"
+ description = "Run an external program with ExecTask"
+ commandLine cmdargs.split()
+}
diff --git a/gradle-5/cmd-line-args/src/main/java/com/baeldung/cmd/MainClass.java b/gradle-5/cmd-line-args/src/main/java/com/baeldung/cmd/MainClass.java
new file mode 100644
index 0000000000..f00aa07d72
--- /dev/null
+++ b/gradle-5/cmd-line-args/src/main/java/com/baeldung/cmd/MainClass.java
@@ -0,0 +1,10 @@
+package com.baeldung.cmd;
+
+public class MainClass {
+ public static void main(String[] args) {
+ System.out.println("Gradle command line arguments example");
+ for (String arg : args) {
+ System.out.println("Got argument [" + arg + "]");
+ }
+ }
+}
diff --git a/gradle-5/settings.gradle b/gradle-5/settings.gradle
index 5384d071e7..ede73daf0a 100644
--- a/gradle-5/settings.gradle
+++ b/gradle-5/settings.gradle
@@ -1,4 +1,5 @@
rootProject.name='gradle-5-articles'
include 'java-exec'
include 'unused-dependencies'
-include 'source-sets'
\ No newline at end of file
+include 'source-sets'
+include 'cmd-line-args'
\ No newline at end of file
diff --git a/java-collections-conversions-2/pom.xml b/java-collections-conversions-2/pom.xml
index 0f7cdadeb2..23f20276a3 100644
--- a/java-collections-conversions-2/pom.xml
+++ b/java-collections-conversions-2/pom.xml
@@ -15,6 +15,12 @@
+
+ org.assertj
+ assertj-core
+ 3.17.2
+ test
+
org.apache.commons
commons-lang3
diff --git a/java-collections-conversions-2/src/test/java/com/baeldung/arrayconversion/ArrayToListConversionUnitTest.java b/java-collections-conversions-2/src/test/java/com/baeldung/arrayconversion/ArrayToListConversionUnitTest.java
index 80e7b93b0c..565c938d48 100644
--- a/java-collections-conversions-2/src/test/java/com/baeldung/arrayconversion/ArrayToListConversionUnitTest.java
+++ b/java-collections-conversions-2/src/test/java/com/baeldung/arrayconversion/ArrayToListConversionUnitTest.java
@@ -1,5 +1,6 @@
package com.baeldung.arrayconversion;
+import org.assertj.core.api.ListAssert;
import org.hamcrest.CoreMatchers;
import org.junit.Test;
@@ -7,8 +8,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertArrayEquals;
+import static org.assertj.core.api.Assertions.assertThat;
public class ArrayToListConversionUnitTest {
@@ -17,8 +17,8 @@ public class ArrayToListConversionUnitTest {
String[] stringArray = new String[] { "A", "B", "C", "D" };
List stringList = Arrays.asList(stringArray);
stringList.set(0, "E");
- assertThat(stringList, CoreMatchers.hasItems("E", "B", "C", "D"));
- assertArrayEquals(stringArray, new String[] { "E", "B", "C", "D" });
+ assertThat(stringList).containsExactly("E", "B", "C", "D");
+ assertThat(stringArray).containsExactly("E", "B", "C", "D");
stringList.add("F");
}
@@ -27,9 +27,9 @@ public class ArrayToListConversionUnitTest {
String[] stringArray = new String[] { "A", "B", "C", "D" };
List stringList = new ArrayList<>(Arrays.asList(stringArray));
stringList.set(0, "E");
- assertThat(stringList, CoreMatchers.hasItems("E", "B", "C", "D"));
- assertArrayEquals(stringArray, new String[] { "A", "B", "C", "D" });
+ assertThat(stringList).containsExactly("E", "B", "C", "D");
+ assertThat(stringArray).containsExactly("A", "B", "C", "D");
stringList.add("F");
- assertThat(stringList, CoreMatchers.hasItems("E", "B", "C", "D", "F"));
+ assertThat(stringList).containsExactly("E", "B", "C", "D", "F");
}
}
diff --git a/jmeter/pom.xml b/jmeter/pom.xml
index 945210edd7..e2830baef5 100644
--- a/jmeter/pom.xml
+++ b/jmeter/pom.xml
@@ -23,6 +23,10 @@
org.springframework.boot
spring-boot-starter-data-rest
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
org.springframework.boot
spring-boot-starter-test
diff --git a/logging-modules/flogger/pom.xml b/logging-modules/flogger/pom.xml
index f553a4a961..e9189c8460 100644
--- a/logging-modules/flogger/pom.xml
+++ b/logging-modules/flogger/pom.xml
@@ -9,6 +9,7 @@
com.baeldung
logging-modules
1.0.0-SNAPSHOT
+ ../pom.xml
diff --git a/logging-modules/log-mdc/pom.xml b/logging-modules/log-mdc/pom.xml
index bc4800ea37..5e2155fde9 100644
--- a/logging-modules/log-mdc/pom.xml
+++ b/logging-modules/log-mdc/pom.xml
@@ -79,6 +79,8 @@
+ logging-service
+
@@ -93,13 +95,21 @@
- logging-service
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.22.2
+
+
2.7
3.3.6
3.3.0.Final
+ 5.6.2
diff --git a/logging-modules/log4j/pom.xml b/logging-modules/log4j/pom.xml
index cc0996a45a..15cd2d530f 100644
--- a/logging-modules/log4j/pom.xml
+++ b/logging-modules/log4j/pom.xml
@@ -9,9 +9,9 @@
com.baeldung
- parent-modules
+ logging-modules
1.0.0-SNAPSHOT
- ../../
+ ../pom.xml
diff --git a/logging-modules/log4j2/pom.xml b/logging-modules/log4j2/pom.xml
index 03a4fd8ab0..e09cbd5d33 100644
--- a/logging-modules/log4j2/pom.xml
+++ b/logging-modules/log4j2/pom.xml
@@ -7,9 +7,9 @@
com.baeldung
- parent-modules
+ logging-modules
1.0.0-SNAPSHOT
- ../../
+ ../pom.xml
diff --git a/logging-modules/logback/pom.xml b/logging-modules/logback/pom.xml
index ee430949df..9f5a3ef294 100644
--- a/logging-modules/logback/pom.xml
+++ b/logging-modules/logback/pom.xml
@@ -9,9 +9,9 @@
com.baeldung
- parent-modules
+ logging-modules
1.0.0-SNAPSHOT
- ../../
+ ../pom.xml
diff --git a/logging-modules/pom.xml b/logging-modules/pom.xml
index b9a1fe77c6..b5354c7c23 100644
--- a/logging-modules/pom.xml
+++ b/logging-modules/pom.xml
@@ -10,7 +10,7 @@
com.baeldung
parent-modules
1.0.0-SNAPSHOT
- ..
+ ../pom.xml
@@ -21,4 +21,17 @@
flogger
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.22.2
+
+
+
+
+
+ 5.6.2
+
diff --git a/parent-boot-2/pom.xml b/parent-boot-2/pom.xml
index ed0f327b8c..dab9f015b3 100644
--- a/parent-boot-2/pom.xml
+++ b/parent-boot-2/pom.xml
@@ -82,7 +82,7 @@
3.3.0
1.0.22.RELEASE
- 2.2.6.RELEASE
+ 2.3.3.RELEASE
1.9.1
diff --git a/persistence-modules/r2dbc/pom.xml b/persistence-modules/r2dbc/pom.xml
index 2da81cba06..119d0547e3 100644
--- a/persistence-modules/r2dbc/pom.xml
+++ b/persistence-modules/r2dbc/pom.xml
@@ -21,6 +21,10 @@
org.springframework.boot
spring-boot-starter-webflux
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
org.springframework.boot
diff --git a/persistence-modules/spring-boot-persistence-mongodb/src/test/java/com/baeldung/mongodb/ManualEmbeddedMongoDbIntegrationTest.java b/persistence-modules/spring-boot-persistence-mongodb/src/test/java/com/baeldung/mongodb/ManualEmbeddedMongoDbIntegrationTest.java
index c49b99ed99..21cf56172e 100644
--- a/persistence-modules/spring-boot-persistence-mongodb/src/test/java/com/baeldung/mongodb/ManualEmbeddedMongoDbIntegrationTest.java
+++ b/persistence-modules/spring-boot-persistence-mongodb/src/test/java/com/baeldung/mongodb/ManualEmbeddedMongoDbIntegrationTest.java
@@ -1,18 +1,8 @@
package com.baeldung.mongodb;
-import static org.assertj.core.api.Assertions.assertThat;
-
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.DisplayName;
-import org.junit.jupiter.api.Test;
-import org.springframework.data.mongodb.core.MongoTemplate;
-import org.springframework.util.SocketUtils;
-
import com.mongodb.BasicDBObjectBuilder;
import com.mongodb.DBObject;
-import com.mongodb.MongoClient;
-
+import com.mongodb.client.MongoClients;
import de.flapdoodle.embed.mongo.MongodExecutable;
import de.flapdoodle.embed.mongo.MongodStarter;
import de.flapdoodle.embed.mongo.config.IMongodConfig;
@@ -20,8 +10,19 @@ import de.flapdoodle.embed.mongo.config.MongodConfigBuilder;
import de.flapdoodle.embed.mongo.config.Net;
import de.flapdoodle.embed.mongo.distribution.Version;
import de.flapdoodle.embed.process.runtime.Network;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.util.SocketUtils;
+
+import static org.assertj.core.api.Assertions.assertThat;
class ManualEmbeddedMongoDbIntegrationTest {
+
+ private static final String CONNECTION_STRING = "mongodb://%s:%d";
+
private MongodExecutable mongodExecutable;
private MongoTemplate mongoTemplate;
@@ -42,7 +43,7 @@ class ManualEmbeddedMongoDbIntegrationTest {
MongodStarter starter = MongodStarter.getDefaultInstance();
mongodExecutable = starter.prepare(mongodConfig);
mongodExecutable.start();
- mongoTemplate = new MongoTemplate(new MongoClient(ip, randomPort), "test");
+ mongoTemplate = new MongoTemplate(MongoClients.create(String.format(CONNECTION_STRING, ip, randomPort)),"test");
}
@DisplayName("Given object When save object using MongoDB template Then object can be found")
diff --git a/persistence-modules/spring-data-cassandra-reactive/pom.xml b/persistence-modules/spring-data-cassandra-reactive/pom.xml
index 70a5f556e2..16486bf380 100644
--- a/persistence-modules/spring-data-cassandra-reactive/pom.xml
+++ b/persistence-modules/spring-data-cassandra-reactive/pom.xml
@@ -51,6 +51,7 @@
+ 2.2.6.RELEASE
3.11.2.0
diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/dao/user/PossessionRepository.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/dao/user/PossessionRepository.java
index ae37fde20d..a5ceee5b1a 100644
--- a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/dao/user/PossessionRepository.java
+++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/dao/user/PossessionRepository.java
@@ -2,8 +2,8 @@ package com.baeldung.multipledb.dao.user;
import org.springframework.data.jpa.repository.JpaRepository;
-import com.baeldung.multipledb.model.user.PossessionMultipleDB;
+import com.baeldung.multipledb.model.user.Possession;
-public interface PossessionRepository extends JpaRepository {
+public interface PossessionRepository extends JpaRepository {
}
diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/dao/user/UserRepository.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/dao/user/UserRepository.java
index 267a61a93f..d3109bd311 100644
--- a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/dao/user/UserRepository.java
+++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/dao/user/UserRepository.java
@@ -2,7 +2,7 @@ package com.baeldung.multipledb.dao.user;
import org.springframework.data.jpa.repository.JpaRepository;
-import com.baeldung.multipledb.model.user.UserMultipleDB;
+import com.baeldung.multipledb.model.user.User;
-public interface UserRepository extends JpaRepository {
+public interface UserRepository extends JpaRepository {
}
\ No newline at end of file
diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/model/user/PossessionMultipleDB.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/model/user/Possession.java
similarity index 89%
rename from persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/model/user/PossessionMultipleDB.java
rename to persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/model/user/Possession.java
index a6a3c88bd0..af646ffd04 100644
--- a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/model/user/PossessionMultipleDB.java
+++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/model/user/Possession.java
@@ -4,7 +4,7 @@ import javax.persistence.*;
@Entity
@Table
-public class PossessionMultipleDB {
+public class Possession {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -12,11 +12,11 @@ public class PossessionMultipleDB {
private String name;
- public PossessionMultipleDB() {
+ public Possession() {
super();
}
- public PossessionMultipleDB(final String name) {
+ public Possession(final String name) {
super();
this.name = name;
@@ -58,7 +58,7 @@ public class PossessionMultipleDB {
if (getClass() != obj.getClass()) {
return false;
}
- final PossessionMultipleDB other = (PossessionMultipleDB) obj;
+ final Possession other = (Possession) obj;
if (id != other.id) {
return false;
}
diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/model/user/UserMultipleDB.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/model/user/User.java
similarity index 82%
rename from persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/model/user/UserMultipleDB.java
rename to persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/model/user/User.java
index c7cd07f7a1..1985c543d3 100644
--- a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/model/user/UserMultipleDB.java
+++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/model/user/User.java
@@ -6,7 +6,7 @@ import java.util.List;
@Entity
@Table(name = "users")
-public class UserMultipleDB {
+public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -18,13 +18,13 @@ public class UserMultipleDB {
private Integer status;
@OneToMany
- List possessionList;
+ List possessionList;
- public UserMultipleDB() {
+ public User() {
super();
}
- public UserMultipleDB(String name, String email, Integer status) {
+ public User(String name, String email, Integer status) {
this.name = name;
this.email = email;
this.status = status;
@@ -70,11 +70,11 @@ public class UserMultipleDB {
this.age = age;
}
- public List getPossessionList() {
+ public List getPossessionList() {
return possessionList;
}
- public void setPossessionList(List possessionList) {
+ public void setPossessionList(List possessionList) {
this.possessionList = possessionList;
}
diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/multipledb/JpaMultipleDBIntegrationTest.java b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/multipledb/JpaMultipleDBIntegrationTest.java
index a1f4a3fa2c..fb363e2ab3 100644
--- a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/multipledb/JpaMultipleDBIntegrationTest.java
+++ b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/multipledb/JpaMultipleDBIntegrationTest.java
@@ -20,8 +20,8 @@ import com.baeldung.multipledb.dao.product.ProductRepository;
import com.baeldung.multipledb.dao.user.PossessionRepository;
import com.baeldung.multipledb.dao.user.UserRepository;
import com.baeldung.multipledb.model.product.Product;
-import com.baeldung.multipledb.model.user.PossessionMultipleDB;
-import com.baeldung.multipledb.model.user.UserMultipleDB;
+import com.baeldung.multipledb.model.user.Possession;
+import com.baeldung.multipledb.model.user.User;
@RunWith(SpringRunner.class)
@SpringBootTest(classes=MultipleDbApplication.class)
@@ -42,15 +42,15 @@ public class JpaMultipleDBIntegrationTest {
@Test
@Transactional("userTransactionManager")
public void whenCreatingUser_thenCreated() {
- UserMultipleDB user = new UserMultipleDB();
+ User user = new User();
user.setName("John");
user.setEmail("john@test.com");
user.setAge(20);
- PossessionMultipleDB p = new PossessionMultipleDB("sample");
+ Possession p = new Possession("sample");
p = possessionRepository.save(p);
user.setPossessionList(Collections.singletonList(p));
user = userRepository.save(user);
- final Optional result = userRepository.findById(user.getId());
+ final Optional result = userRepository.findById(user.getId());
assertTrue(result.isPresent());
System.out.println(result.get().getPossessionList());
assertEquals(1, result.get().getPossessionList().size());
@@ -59,14 +59,14 @@ public class JpaMultipleDBIntegrationTest {
@Test
@Transactional("userTransactionManager")
public void whenCreatingUsersWithSameEmail_thenRollback() {
- UserMultipleDB user1 = new UserMultipleDB();
+ User user1 = new User();
user1.setName("John");
user1.setEmail("john@test.com");
user1.setAge(20);
user1 = userRepository.save(user1);
assertTrue(userRepository.findById(user1.getId()).isPresent());
- UserMultipleDB user2 = new UserMultipleDB();
+ User user2 = new User();
user2.setName("Tom");
user2.setEmail("john@test.com");
user2.setAge(10);
diff --git a/software-security/sql-injection-samples/src/main/resources/application.properties b/software-security/sql-injection-samples/src/main/resources/application.properties
index 8b13789179..953384eac4 100644
--- a/software-security/sql-injection-samples/src/main/resources/application.properties
+++ b/software-security/sql-injection-samples/src/main/resources/application.properties
@@ -1 +1 @@
-
+spring.data.jpa.repositories.bootstrap-mode=default
diff --git a/spring-5-data-reactive/pom.xml b/spring-5-data-reactive/pom.xml
index aeaf6daf1a..396f7f5959 100644
--- a/spring-5-data-reactive/pom.xml
+++ b/spring-5-data-reactive/pom.xml
@@ -224,6 +224,7 @@
1.4.200
1.5.23
3.3.1.RELEASE
+ 2.2.6.RELEASE
diff --git a/spring-5-reactive-2/pom.xml b/spring-5-reactive-2/pom.xml
index 4cb85d879e..093be0f03c 100644
--- a/spring-5-reactive-2/pom.xml
+++ b/spring-5-reactive-2/pom.xml
@@ -20,6 +20,10 @@
org.springframework.boot
spring-boot-starter-webflux
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
org.springframework.boot
spring-boot-starter-security
diff --git a/spring-5-reactive-security/src/main/java/com/baeldung/reactive/authresolver/CustomWebSecurityConfig.java b/spring-5-reactive-security/src/main/java/com/baeldung/reactive/authresolver/CustomWebSecurityConfig.java
index d07a991089..dc5eab3dd5 100644
--- a/spring-5-reactive-security/src/main/java/com/baeldung/reactive/authresolver/CustomWebSecurityConfig.java
+++ b/spring-5-reactive-security/src/main/java/com/baeldung/reactive/authresolver/CustomWebSecurityConfig.java
@@ -2,7 +2,6 @@ package com.baeldung.reactive.authresolver;
import java.util.Collections;
import org.springframework.context.annotation.Bean;
-import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.security.authentication.ReactiveAuthenticationManager;
import org.springframework.security.authentication.ReactiveAuthenticationManagerResolver;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
@@ -15,6 +14,7 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.web.server.SecurityWebFilterChain;
import org.springframework.security.web.server.authentication.AuthenticationWebFilter;
+import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
@EnableWebFluxSecurity
@@ -38,9 +38,10 @@ public class CustomWebSecurityConfig {
return new AuthenticationWebFilter(resolver());
}
- public ReactiveAuthenticationManagerResolver resolver() {
- return request -> {
- if (request
+ public ReactiveAuthenticationManagerResolver resolver() {
+ return exchange -> {
+ if (exchange
+ .getRequest()
.getPath()
.subPath(0)
.value()
diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/errorhandling/GlobalErrorAttributes.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/errorhandling/GlobalErrorAttributes.java
index a50651ced7..5885ac50d0 100644
--- a/spring-5-reactive/src/main/java/com/baeldung/reactive/errorhandling/GlobalErrorAttributes.java
+++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/errorhandling/GlobalErrorAttributes.java
@@ -2,6 +2,8 @@
package com.baeldung.reactive.errorhandling;
import java.util.Map;
+
+import org.springframework.boot.web.error.ErrorAttributeOptions;
import org.springframework.boot.web.reactive.error.DefaultErrorAttributes;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
@@ -13,13 +15,9 @@ public class GlobalErrorAttributes extends DefaultErrorAttributes{
private HttpStatus status = HttpStatus.BAD_REQUEST;
private String message = "please provide a name";
- public GlobalErrorAttributes() {
- super(false);
- }
-
@Override
- public Map getErrorAttributes(ServerRequest request, boolean includeStackTrace) {
- Map map = super.getErrorAttributes(request, includeStackTrace);
+ public Map getErrorAttributes(ServerRequest request, ErrorAttributeOptions options) {
+ Map map = super.getErrorAttributes(request, options);
map.put("status", getStatus());
map.put("message", getMessage());
return map;
diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/errorhandling/GlobalErrorWebExceptionHandler.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/errorhandling/GlobalErrorWebExceptionHandler.java
index 09bccb0d5e..051e4b8df5 100644
--- a/spring-5-reactive/src/main/java/com/baeldung/reactive/errorhandling/GlobalErrorWebExceptionHandler.java
+++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/errorhandling/GlobalErrorWebExceptionHandler.java
@@ -4,6 +4,7 @@ package com.baeldung.reactive.errorhandling;
import java.util.Map;
import org.springframework.boot.autoconfigure.web.ResourceProperties;
import org.springframework.boot.autoconfigure.web.reactive.error.AbstractErrorWebExceptionHandler;
+import org.springframework.boot.web.error.ErrorAttributeOptions;
import org.springframework.boot.web.reactive.error.ErrorAttributes;
import org.springframework.context.ApplicationContext;
import org.springframework.core.annotation.Order;
@@ -37,7 +38,7 @@ public class GlobalErrorWebExceptionHandler extends AbstractErrorWebExceptionHan
private Mono renderErrorResponse(final ServerRequest request) {
- final Map errorPropertiesMap = getErrorAttributes(request, false);
+ final Map errorPropertiesMap = getErrorAttributes(request, ErrorAttributeOptions.defaults());
return ServerResponse.status(HttpStatus.BAD_REQUEST)
.contentType(MediaType.APPLICATION_JSON_UTF8)
diff --git a/spring-boot-modules/spring-boot-angular/pom.xml b/spring-boot-modules/spring-boot-angular/pom.xml
index 4b3ac27834..ac63d21bb8 100644
--- a/spring-boot-modules/spring-boot-angular/pom.xml
+++ b/spring-boot-modules/spring-boot-angular/pom.xml
@@ -26,6 +26,10 @@
org.springframework.boot
spring-boot-starter-web
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
com.h2database
h2
diff --git a/spring-boot-modules/spring-boot-autoconfiguration/pom.xml b/spring-boot-modules/spring-boot-autoconfiguration/pom.xml
index 5709d1d796..269d87bbb9 100644
--- a/spring-boot-modules/spring-boot-autoconfiguration/pom.xml
+++ b/spring-boot-modules/spring-boot-autoconfiguration/pom.xml
@@ -26,6 +26,10 @@
org.springframework.boot
spring-boot-starter-web
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
org.springframework.boot
spring-boot-starter-data-jpa
diff --git a/spring-boot-modules/spring-boot-crud/pom.xml b/spring-boot-modules/spring-boot-crud/pom.xml
index a4be360b0f..cf1bfe6da0 100644
--- a/spring-boot-modules/spring-boot-crud/pom.xml
+++ b/spring-boot-modules/spring-boot-crud/pom.xml
@@ -20,6 +20,10 @@
org.springframework.boot
spring-boot-starter-web
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
org.springframework.boot
spring-boot-starter-thymeleaf
diff --git a/spring-boot-modules/spring-boot-mvc-2/pom.xml b/spring-boot-modules/spring-boot-mvc-2/pom.xml
index 0b9213a7ea..580224cfd0 100644
--- a/spring-boot-modules/spring-boot-mvc-2/pom.xml
+++ b/spring-boot-modules/spring-boot-mvc-2/pom.xml
@@ -23,6 +23,11 @@
spring-boot-starter-web
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
+
org.springframework.boot
spring-boot-devtools
diff --git a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/swagger2boot/plugin/EmailAnnotationPlugin.java b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/swagger2boot/plugin/EmailAnnotationPlugin.java
index 22ca144fb4..59a7c97080 100644
--- a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/swagger2boot/plugin/EmailAnnotationPlugin.java
+++ b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/swagger2boot/plugin/EmailAnnotationPlugin.java
@@ -10,6 +10,7 @@ import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import springfox.bean.validators.plugins.Validators;
+import springfox.documentation.builders.StringElementFacetBuilder;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.schema.ModelPropertyBuilderPlugin;
import springfox.documentation.spi.schema.contexts.ModelPropertyContext;
@@ -30,8 +31,9 @@ public class EmailAnnotationPlugin implements ModelPropertyBuilderPlugin {
public void apply(ModelPropertyContext context) {
Optional email = annotationFromBean(context, Email.class);
if (email.isPresent()) {
- context.getBuilder().pattern(email.get().regexp());
- context.getBuilder().example("email@email.com");
+ context.getSpecificationBuilder().facetBuilder(StringElementFacetBuilder.class)
+ .pattern(email.get().regexp());
+ context.getSpecificationBuilder().example("email@email.com");
}
}
diff --git a/spring-boot-modules/spring-boot-properties/pom.xml b/spring-boot-modules/spring-boot-properties/pom.xml
index a5594ee2de..cfdc71b8d6 100644
--- a/spring-boot-modules/spring-boot-properties/pom.xml
+++ b/spring-boot-modules/spring-boot-properties/pom.xml
@@ -27,6 +27,10 @@
org.springframework.boot
spring-boot-starter-web
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
org.springframework.boot
spring-boot-starter-actuator
diff --git a/spring-boot-modules/spring-boot-runtime/pom.xml b/spring-boot-modules/spring-boot-runtime/pom.xml
index d3966beb65..ce6fa7ea93 100644
--- a/spring-boot-modules/spring-boot-runtime/pom.xml
+++ b/spring-boot-modules/spring-boot-runtime/pom.xml
@@ -29,6 +29,11 @@
spring-boot-starter-web
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
+
org.springframework.boot
spring-boot-starter-thymeleaf
diff --git a/spring-boot-modules/spring-boot-springdoc/pom.xml b/spring-boot-modules/spring-boot-springdoc/pom.xml
index 3e8d5175f7..ed272200da 100644
--- a/spring-boot-modules/spring-boot-springdoc/pom.xml
+++ b/spring-boot-modules/spring-boot-springdoc/pom.xml
@@ -24,6 +24,10 @@
org.springframework.boot
spring-boot-starter-web
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
org.springframework.boot
spring-boot-starter-data-jpa
diff --git a/spring-boot-modules/spring-boot-testing/pom.xml b/spring-boot-modules/spring-boot-testing/pom.xml
index bd5ef901dd..5bf626f165 100644
--- a/spring-boot-modules/spring-boot-testing/pom.xml
+++ b/spring-boot-modules/spring-boot-testing/pom.xml
@@ -26,6 +26,10 @@
org.springframework.boot
spring-boot-starter-web
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
org.springframework.boot
spring-boot-starter-tomcat
diff --git a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/testloglevel/LogbackMultiProfileTestLogLevelIntegrationTest.java b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/testloglevel/LogbackMultiProfileTestLogLevelIntegrationTest.java
index ffe99672be..b3d80a7d8b 100644
--- a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/testloglevel/LogbackMultiProfileTestLogLevelIntegrationTest.java
+++ b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/testloglevel/LogbackMultiProfileTestLogLevelIntegrationTest.java
@@ -8,7 +8,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
-import org.springframework.boot.test.rule.OutputCapture;
+import org.springframework.boot.test.system.OutputCaptureRule;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext;
@@ -29,7 +29,7 @@ public class LogbackMultiProfileTestLogLevelIntegrationTest {
private TestRestTemplate restTemplate;
@Rule
- public OutputCapture outputCapture = new OutputCapture();
+ public OutputCaptureRule outputCapture = new OutputCaptureRule();
private String baseUrl = "/testLogLevel";
diff --git a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/testloglevel/LogbackTestLogLevelIntegrationTest.java b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/testloglevel/LogbackTestLogLevelIntegrationTest.java
index cbd22e8087..f60a5e0ee3 100644
--- a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/testloglevel/LogbackTestLogLevelIntegrationTest.java
+++ b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/testloglevel/LogbackTestLogLevelIntegrationTest.java
@@ -8,7 +8,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
-import org.springframework.boot.test.rule.OutputCapture;
+import org.springframework.boot.test.system.OutputCaptureRule;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext;
@@ -29,7 +29,7 @@ public class LogbackTestLogLevelIntegrationTest {
private TestRestTemplate restTemplate;
@Rule
- public OutputCapture outputCapture = new OutputCapture();
+ public OutputCaptureRule outputCapture = new OutputCaptureRule();
private String baseUrl = "/testLogLevel";
diff --git a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/testloglevel/TestLogLevelWithProfileIntegrationTest.java b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/testloglevel/TestLogLevelWithProfileIntegrationTest.java
index 571b826b80..e59b673a1c 100644
--- a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/testloglevel/TestLogLevelWithProfileIntegrationTest.java
+++ b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/testloglevel/TestLogLevelWithProfileIntegrationTest.java
@@ -8,7 +8,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
-import org.springframework.boot.test.rule.OutputCapture;
+import org.springframework.boot.test.system.OutputCaptureRule;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext;
@@ -29,7 +29,7 @@ public class TestLogLevelWithProfileIntegrationTest {
private TestRestTemplate restTemplate;
@Rule
- public OutputCapture outputCapture = new OutputCapture();
+ public OutputCaptureRule outputCapture = new OutputCaptureRule();
private String baseUrl = "/testLogLevel";
diff --git a/spring-boot-modules/spring-boot/pom.xml b/spring-boot-modules/spring-boot/pom.xml
index 5efcffdf03..c1f1ea3072 100644
--- a/spring-boot-modules/spring-boot/pom.xml
+++ b/spring-boot-modules/spring-boot/pom.xml
@@ -27,6 +27,10 @@
org.springframework.boot
spring-boot-starter-web
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
org.springframework.boot
spring-boot-starter-data-jpa
@@ -98,11 +102,6 @@
rome
${rome.version}
-
-
- javax.validation
- validation-api
-
diff --git a/spring-cloud/spring-cloud-connectors-heroku/pom.xml b/spring-cloud/spring-cloud-connectors-heroku/pom.xml
index c09a282197..7d85e07bb8 100644
--- a/spring-cloud/spring-cloud-connectors-heroku/pom.xml
+++ b/spring-cloud/spring-cloud-connectors-heroku/pom.xml
@@ -60,6 +60,7 @@
+ 2.2.6.RELEASE
Hoxton.SR4
42.2.10
1.10.10
diff --git a/spring-cloud/spring-cloud-vault/pom.xml b/spring-cloud/spring-cloud-vault/pom.xml
index a5a29d9024..d9ae6b515f 100644
--- a/spring-cloud/spring-cloud-vault/pom.xml
+++ b/spring-cloud/spring-cloud-vault/pom.xml
@@ -62,6 +62,10 @@
org.springframework.boot
spring-boot-starter-web
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
org.springframework.boot
spring-boot-starter-data-jpa
diff --git a/spring-jenkins-pipeline/pom.xml b/spring-jenkins-pipeline/pom.xml
index 38d4ed15de..152e107409 100644
--- a/spring-jenkins-pipeline/pom.xml
+++ b/spring-jenkins-pipeline/pom.xml
@@ -24,6 +24,10 @@
org.springframework.boot
spring-boot-starter-data-rest
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
org.springframework.boot
spring-boot-starter-test
diff --git a/spring-mvc-basics-2/pom.xml b/spring-mvc-basics-2/pom.xml
index 026ddf8e72..6bcb1e90e5 100644
--- a/spring-mvc-basics-2/pom.xml
+++ b/spring-mvc-basics-2/pom.xml
@@ -69,7 +69,7 @@
org.thymeleaf
- thymeleaf-spring4
+ thymeleaf-spring5
${org.thymeleaf-version}
@@ -164,7 +164,7 @@
6.0.10.Final
enter-location-of-server
1.3.2
- 3.0.7.RELEASE
+ 3.0.11.RELEASE
2.4.12
2.3.27-incubating
1.2.5
diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/EmailConfiguration.java b/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/EmailConfiguration.java
index 1bbbc51304..4bd692f609 100644
--- a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/EmailConfiguration.java
+++ b/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/EmailConfiguration.java
@@ -11,8 +11,8 @@ import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
-import org.thymeleaf.spring4.SpringTemplateEngine;
-import org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver;
+import org.thymeleaf.spring5.SpringTemplateEngine;
+import org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver;
@Configuration
@ComponentScan(basePackages = { "com.baeldung.spring.mail" })
diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/ThymeleafConfiguration.java b/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/ThymeleafConfiguration.java
index 257dbc718a..2f025c1ad2 100644
--- a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/ThymeleafConfiguration.java
+++ b/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/ThymeleafConfiguration.java
@@ -4,9 +4,9 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
-import org.thymeleaf.spring4.SpringTemplateEngine;
-import org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver;
-import org.thymeleaf.spring4.view.ThymeleafViewResolver;
+import org.thymeleaf.spring5.SpringTemplateEngine;
+import org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver;
+import org.thymeleaf.spring5.view.ThymeleafViewResolver;
@Configuration
@EnableWebMvc
diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/mail/EmailServiceImpl.java b/spring-mvc-basics-2/src/main/java/com/baeldung/spring/mail/EmailServiceImpl.java
index cbcb8f4e34..1eb7a5f8b4 100644
--- a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/mail/EmailServiceImpl.java
+++ b/spring-mvc-basics-2/src/main/java/com/baeldung/spring/mail/EmailServiceImpl.java
@@ -19,7 +19,7 @@ import org.springframework.stereotype.Service;
import org.springframework.ui.freemarker.FreeMarkerTemplateUtils;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
import org.thymeleaf.context.Context;
-import org.thymeleaf.spring4.SpringTemplateEngine;
+import org.thymeleaf.spring5.SpringTemplateEngine;
import freemarker.template.Template;
import freemarker.template.TemplateException;
diff --git a/spring-mvc-basics-3/pom.xml b/spring-mvc-basics-3/pom.xml
index 1dea8f9e93..a929337b25 100644
--- a/spring-mvc-basics-3/pom.xml
+++ b/spring-mvc-basics-3/pom.xml
@@ -21,6 +21,11 @@
spring-boot-starter-web
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
+
org.springframework.boot
spring-boot-starter-test
diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/Article.java b/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/Article.java
index f6675295ed..5a9f406b56 100644
--- a/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/Article.java
+++ b/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/Article.java
@@ -1,4 +1,4 @@
-package com.baeldung.controller.optionalpathvars;
+package com.baeldung.optionalpathvars;
public class Article {
diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerController.java b/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerController.java
index 14b16e148b..1876798bd6 100644
--- a/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerController.java
+++ b/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerController.java
@@ -1,6 +1,6 @@
-package com.baeldung.controller.optionalpathvars;
+package com.baeldung.optionalpathvars;
-import static com.baeldung.controller.optionalpathvars.Article.DEFAULT_ARTICLE;
+import static com.baeldung.optionalpathvars.Article.DEFAULT_ARTICLE;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerWithMapParamController.java b/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerWithMapParamController.java
index 50744b6067..c989ddfa52 100644
--- a/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerWithMapParamController.java
+++ b/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerWithMapParamController.java
@@ -1,6 +1,6 @@
-package com.baeldung.controller.optionalpathvars;
+package com.baeldung.optionalpathvars;
-import static com.baeldung.controller.optionalpathvars.Article.DEFAULT_ARTICLE;
+import static com.baeldung.optionalpathvars.Article.DEFAULT_ARTICLE;
import java.util.Map;
diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerWithOptionalParamController.java b/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerWithOptionalParamController.java
index ff645fbcc7..75e35bf799 100644
--- a/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerWithOptionalParamController.java
+++ b/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerWithOptionalParamController.java
@@ -1,6 +1,6 @@
-package com.baeldung.controller.optionalpathvars;
+package com.baeldung.optionalpathvars;
-import static com.baeldung.controller.optionalpathvars.Article.DEFAULT_ARTICLE;
+import static com.baeldung.optionalpathvars.Article.DEFAULT_ARTICLE;
import java.util.Optional;
diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerWithRequiredAttributeController.java b/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerWithRequiredAttributeController.java
index 8cd1539391..7548747f05 100644
--- a/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerWithRequiredAttributeController.java
+++ b/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerWithRequiredAttributeController.java
@@ -1,6 +1,6 @@
-package com.baeldung.controller.optionalpathvars;
+package com.baeldung.optionalpathvars;
-import static com.baeldung.controller.optionalpathvars.Article.DEFAULT_ARTICLE;
+import static com.baeldung.optionalpathvars.Article.DEFAULT_ARTICLE;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
diff --git a/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerWithTwoSeparateMethodsController.java b/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerWithTwoSeparateMethodsController.java
index 0ea401a589..beb520c1b4 100644
--- a/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerWithTwoSeparateMethodsController.java
+++ b/spring-mvc-basics-4/src/main/java/com/baeldung/optionalpathvars/ArticleViewerWithTwoSeparateMethodsController.java
@@ -1,6 +1,6 @@
-package com.baeldung.controller.optionalpathvars;
+package com.baeldung.optionalpathvars;
-import static com.baeldung.controller.optionalpathvars.Article.DEFAULT_ARTICLE;
+import static com.baeldung.optionalpathvars.Article.DEFAULT_ARTICLE;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
diff --git a/spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerControllerIntegrationTest.java b/spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerControllerIntegrationTest.java
index 173ac165c3..0e2313c2ac 100644
--- a/spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerControllerIntegrationTest.java
+++ b/spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerControllerIntegrationTest.java
@@ -1,4 +1,4 @@
-package com.baeldung.controller.optionalpathvars;
+package com.baeldung.optionalpathvars;
import org.junit.Before;
import org.junit.Test;
diff --git a/spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerControllerWithOptionalParamIntegrationTest.java b/spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerControllerWithOptionalParamIntegrationTest.java
index 1fadfb7038..094995ba67 100644
--- a/spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerControllerWithOptionalParamIntegrationTest.java
+++ b/spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerControllerWithOptionalParamIntegrationTest.java
@@ -1,4 +1,4 @@
-package com.baeldung.controller.optionalpathvars;
+package com.baeldung.optionalpathvars;
import org.junit.Before;
import org.junit.Test;
diff --git a/spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerControllerWithRequiredAttributeIntegrationTest.java b/spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerControllerWithRequiredAttributeIntegrationTest.java
index 00d620ef9a..a4b12c7163 100644
--- a/spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerControllerWithRequiredAttributeIntegrationTest.java
+++ b/spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerControllerWithRequiredAttributeIntegrationTest.java
@@ -1,4 +1,4 @@
-package com.baeldung.controller.optionalpathvars;
+package com.baeldung.optionalpathvars;
import org.junit.Before;
import org.junit.Test;
diff --git a/spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerWithMapParamIntegrationTest.java b/spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerWithMapParamIntegrationTest.java
index f7fff714a9..044a1c8bce 100644
--- a/spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerWithMapParamIntegrationTest.java
+++ b/spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerWithMapParamIntegrationTest.java
@@ -1,4 +1,4 @@
-package com.baeldung.controller.optionalpathvars;
+package com.baeldung.optionalpathvars;
import org.junit.Before;
import org.junit.Test;
diff --git a/spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerWithTwoSeparateMethodsIntegrationTest.java b/spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerWithTwoSeparateMethodsIntegrationTest.java
index b4e4c9ade5..1ca926277d 100644
--- a/spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerWithTwoSeparateMethodsIntegrationTest.java
+++ b/spring-mvc-basics-4/src/test/java/com/baeldung/optionalpathvars/ArticleViewerWithTwoSeparateMethodsIntegrationTest.java
@@ -1,4 +1,4 @@
-package com.baeldung.controller.optionalpathvars;
+package com.baeldung.optionalpathvars;
import org.junit.Before;
import org.junit.Test;
diff --git a/spring-mvc-basics/pom.xml b/spring-mvc-basics/pom.xml
index 159dda955f..d212bc425a 100644
--- a/spring-mvc-basics/pom.xml
+++ b/spring-mvc-basics/pom.xml
@@ -20,6 +20,10 @@
org.springframework.boot
spring-boot-starter-web
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
org.apache.tomcat.embed
diff --git a/spring-mvc-java/pom.xml b/spring-mvc-java/pom.xml
index 9e3457aa8a..a45e9c8521 100644
--- a/spring-mvc-java/pom.xml
+++ b/spring-mvc-java/pom.xml
@@ -42,12 +42,6 @@
tomcat-embed-jasper
provided
-
-
- com.fasterxml.jackson.core
- jackson-databind
- ${jackson.version}
-
net.sourceforge.htmlunit
diff --git a/spring-rest-hal-browser/pom.xml b/spring-rest-hal-browser/pom.xml
index 7b629dba44..c8066b89a4 100644
--- a/spring-rest-hal-browser/pom.xml
+++ b/spring-rest-hal-browser/pom.xml
@@ -20,6 +20,10 @@
org.springframework.boot
spring-boot-starter-web
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
org.springframework.boot
diff --git a/spring-rest-http/pom.xml b/spring-rest-http/pom.xml
index 32d2804220..18b7e0af05 100644
--- a/spring-rest-http/pom.xml
+++ b/spring-rest-http/pom.xml
@@ -20,6 +20,10 @@
org.springframework.boot
spring-boot-starter-web
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
org.springframework
spring-oxm
diff --git a/spring-scheduling/src/main/java/com/baeldung/springretry/AppConfig.java b/spring-scheduling/src/main/java/com/baeldung/springretry/AppConfig.java
index e79beb370b..2ca9104e89 100644
--- a/spring-scheduling/src/main/java/com/baeldung/springretry/AppConfig.java
+++ b/spring-scheduling/src/main/java/com/baeldung/springretry/AppConfig.java
@@ -3,6 +3,7 @@ package com.baeldung.springretry;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.PropertySource;
import org.springframework.retry.annotation.EnableRetry;
import org.springframework.retry.backoff.FixedBackOffPolicy;
import org.springframework.retry.policy.SimpleRetryPolicy;
@@ -11,9 +12,7 @@ import org.springframework.retry.support.RetryTemplate;
@Configuration
@ComponentScan(basePackages = "com.baeldung.springretry")
@EnableRetry
-// Uncomment this two lines if we need XML configuration
-// @EnableAspectJAutoProxy
-// @ImportResource("classpath:/retryadvice.xml")
+@PropertySource("classpath:retryConfig.properties")
public class AppConfig {
@Bean
diff --git a/spring-scheduling/src/main/java/com/baeldung/springretry/MyService.java b/spring-scheduling/src/main/java/com/baeldung/springretry/MyService.java
index 409bf25845..40e2c419fc 100644
--- a/spring-scheduling/src/main/java/com/baeldung/springretry/MyService.java
+++ b/spring-scheduling/src/main/java/com/baeldung/springretry/MyService.java
@@ -2,18 +2,27 @@ package com.baeldung.springretry;
import java.sql.SQLException;
+import org.springframework.context.annotation.PropertySource;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Recover;
import org.springframework.retry.annotation.Retryable;
+
public interface MyService {
@Retryable
void retryService();
- @Retryable(value = { SQLException.class }, maxAttempts = 2, backoff = @Backoff(delay = 5000))
+ @Retryable(value = SQLException.class)
void retryServiceWithRecovery(String sql) throws SQLException;
+ @Retryable(value = { SQLException.class }, maxAttempts = 2, backoff = @Backoff(delay = 100))
+ void retryServiceWithCustomization(String sql) throws SQLException;
+
+ @Retryable( value = SQLException.class, maxAttemptsExpression = "${retry.maxAttempts}",
+ backoff = @Backoff(delayExpression = "${retry.maxDelay}"))
+ void retryServiceWithExternalConfiguration(String sql) throws SQLException;
+
@Recover
void recover(SQLException e, String sql);
diff --git a/spring-scheduling/src/main/java/com/baeldung/springretry/MyServiceImpl.java b/spring-scheduling/src/main/java/com/baeldung/springretry/MyServiceImpl.java
index 3e4b5ed00d..7eb4328a47 100644
--- a/spring-scheduling/src/main/java/com/baeldung/springretry/MyServiceImpl.java
+++ b/spring-scheduling/src/main/java/com/baeldung/springretry/MyServiceImpl.java
@@ -26,6 +26,22 @@ public class MyServiceImpl implements MyService {
}
}
+ @Override
+ public void retryServiceWithCustomization(String sql) throws SQLException {
+ if (StringUtils.isEmpty(sql)) {
+ logger.info("throw SQLException in method retryServiceWithCustomization()");
+ throw new SQLException();
+ }
+ }
+
+ @Override
+ public void retryServiceWithExternalConfiguration(String sql) throws SQLException {
+ if (StringUtils.isEmpty(sql)) {
+ logger.info("throw SQLException in method retryServiceWithExternalConfiguration()");
+ throw new SQLException();
+ }
+ }
+
@Override
public void recover(SQLException e, String sql) {
logger.info("In recover method");
diff --git a/spring-scheduling/src/main/resources/retryConfig.properties b/spring-scheduling/src/main/resources/retryConfig.properties
new file mode 100644
index 0000000000..7cc360adc6
--- /dev/null
+++ b/spring-scheduling/src/main/resources/retryConfig.properties
@@ -0,0 +1,2 @@
+retry.maxAttempts=2
+retry.maxDelay=100
\ No newline at end of file
diff --git a/spring-scheduling/src/main/resources/retryadvice.xml b/spring-scheduling/src/main/resources/retryadvice.xml
deleted file mode 100644
index 8de7801a58..0000000000
--- a/spring-scheduling/src/main/resources/retryadvice.xml
+++ /dev/null
@@ -1,50 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Initial sleep interval value, default 300 ms
-
-
-
-
- The maximum value of the backoff period in milliseconds.
-
-
-
-
- The value to increment the exp seed with for each retry attempt.
-
-
-
-
-
\ No newline at end of file
diff --git a/spring-scheduling/src/test/java/com/baeldung/springretry/SpringRetryIntegrationTest.java b/spring-scheduling/src/test/java/com/baeldung/springretry/SpringRetryIntegrationTest.java
index 2e5fb75482..33ce2fff74 100644
--- a/spring-scheduling/src/test/java/com/baeldung/springretry/SpringRetryIntegrationTest.java
+++ b/spring-scheduling/src/test/java/com/baeldung/springretry/SpringRetryIntegrationTest.java
@@ -30,6 +30,16 @@ public class SpringRetryIntegrationTest {
myService.retryServiceWithRecovery(null);
}
+ @Test
+ public void givenRetryServiceWithCustomization_whenCallWithException_thenRetryRecover() throws SQLException {
+ myService.retryServiceWithCustomization(null);
+ }
+
+ @Test
+ public void givenRetryServiceWithExternalConfiguration_whenCallWithException_thenRetryRecover() throws SQLException {
+ myService.retryServiceWithExternalConfiguration(null);
+ }
+
@Test(expected = RuntimeException.class)
public void givenTemplateRetryService_whenCallWithException_thenRetry() {
retryTemplate.execute(arg0 -> {
diff --git a/spring-session/spring-session-jdbc/src/main/resources/application.properties b/spring-session/spring-session-jdbc/src/main/resources/application.properties
index 119638de31..bb9dd24590 100644
--- a/spring-session/spring-session-jdbc/src/main/resources/application.properties
+++ b/spring-session/spring-session-jdbc/src/main/resources/application.properties
@@ -1,3 +1,4 @@
+spring.datasource.generate-unique-name=false
spring.session.store-type=jdbc
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console
\ No newline at end of file
diff --git a/spring-thymeleaf-2/pom.xml b/spring-thymeleaf-2/pom.xml
index 24c159dab9..43f36d9887 100644
--- a/spring-thymeleaf-2/pom.xml
+++ b/spring-thymeleaf-2/pom.xml
@@ -18,6 +18,10 @@
org.springframework.boot
spring-boot-starter-web
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
org.springframework.boot
spring-boot-starter-thymeleaf
diff --git a/spring-thymeleaf-3/pom.xml b/spring-thymeleaf-3/pom.xml
index 7677e50d79..7c58115d11 100644
--- a/spring-thymeleaf-3/pom.xml
+++ b/spring-thymeleaf-3/pom.xml
@@ -18,6 +18,10 @@
org.springframework.boot
spring-boot-starter-web
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
org.springframework.boot
spring-boot-starter-thymeleaf
diff --git a/spring-thymeleaf/pom.xml b/spring-thymeleaf/pom.xml
index c37c66a36d..30f77dd73e 100644
--- a/spring-thymeleaf/pom.xml
+++ b/spring-thymeleaf/pom.xml
@@ -145,10 +145,10 @@
- 2.0.9.RELEASE
- 3.0.9.RELEASE
- 3.0.1.RELEASE
- 2.3.0
+ 2.3.2.RELEASE
+ 3.0.11.RELEASE
+ 3.0.4.RELEASE
+ 2.4.1
2.0.1.Final
6.0.11.Final
diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/junit5/nonstatic/BeforeAndAfterAnnotationsUnitTest.java b/testing-modules/junit-5/src/test/java/com/baeldung/junit5/nonstatic/BeforeAndAfterAnnotationsUnitTest.java
new file mode 100644
index 0000000000..1bfea8447b
--- /dev/null
+++ b/testing-modules/junit-5/src/test/java/com/baeldung/junit5/nonstatic/BeforeAndAfterAnnotationsUnitTest.java
@@ -0,0 +1,27 @@
+package com.baeldung.junit5.nonstatic;
+
+import org.junit.jupiter.api.*;
+
+@TestInstance(TestInstance.Lifecycle.PER_CLASS)
+public class BeforeAndAfterAnnotationsUnitTest {
+
+ String input;
+ Long result;
+
+ @BeforeAll
+ public void setup() {
+ input = "77";
+ }
+
+ @AfterAll
+ public void teardown() {
+ input = null;
+ result = null;
+ }
+
+ @Test
+ public void whenConvertStringToLong_thenResultShouldBeLong() {
+ result = Long.valueOf(input);
+ Assertions.assertEquals(77l, result);
+ }
+}
diff --git a/testing-modules/rest-assured/pom.xml b/testing-modules/rest-assured/pom.xml
index 0b027312d6..eeb5389f49 100644
--- a/testing-modules/rest-assured/pom.xml
+++ b/testing-modules/rest-assured/pom.xml
@@ -102,6 +102,7 @@
joda-time
joda-time
+ ${joda-time.version}