From 684ee81ed1828c1e8a38e4b320379a4c4768b583 Mon Sep 17 00:00:00 2001 From: vunamtien Date: Sun, 14 Apr 2024 22:04:50 +0700 Subject: [PATCH] [JAVA-32759] Split-or-move-spring-boot-persistence-mongodb (#16392) --- persistence-modules/pom.xml | 1 + .../README.md | 5 +++ .../spring-boot-persistence-mongodb-4/pom.xml | 34 +++++++++++++++++++ .../mongodb/dbref/DbRefApplication.java | 0 .../baeldung/mongodb/dbref/DbRefTester.java | 3 +- .../baeldung/mongodb/dbref/model/Person.java | 4 +-- .../com/baeldung/mongodb/dbref/model/Pet.java | 0 .../dbref/repository/PersonRepository.java | 3 +- .../zoneddatetime/config/MongoConfig.java | 9 +++-- .../converter/ZonedDateTimeReadConverter.java | 0 .../ZonedDateTimeWriteConverter.java | 0 .../baeldung/zoneddatetime/model/Action.java | 0 .../repository/ActionRepository.java | 3 +- .../src/main/resources/application.properties | 1 + .../mongodb/dbref/DbRefIntegrationTest.java | 23 ++++++------- .../ActionRepositoryLiveTest.java | 7 ++-- .../src/test/resources/application.properties | 1 + .../spring-boot-persistence-mongodb/README.md | 2 -- 18 files changed, 65 insertions(+), 31 deletions(-) create mode 100644 persistence-modules/spring-boot-persistence-mongodb-4/README.md create mode 100644 persistence-modules/spring-boot-persistence-mongodb-4/pom.xml rename persistence-modules/{spring-boot-persistence-mongodb => spring-boot-persistence-mongodb-4}/src/main/java/com/baeldung/mongodb/dbref/DbRefApplication.java (100%) rename persistence-modules/{spring-boot-persistence-mongodb => spring-boot-persistence-mongodb-4}/src/main/java/com/baeldung/mongodb/dbref/DbRefTester.java (99%) rename persistence-modules/{spring-boot-persistence-mongodb => spring-boot-persistence-mongodb-4}/src/main/java/com/baeldung/mongodb/dbref/model/Person.java (100%) rename persistence-modules/{spring-boot-persistence-mongodb => spring-boot-persistence-mongodb-4}/src/main/java/com/baeldung/mongodb/dbref/model/Pet.java (100%) rename persistence-modules/{spring-boot-persistence-mongodb => spring-boot-persistence-mongodb-4}/src/main/java/com/baeldung/mongodb/dbref/repository/PersonRepository.java (99%) rename persistence-modules/{spring-boot-persistence-mongodb => spring-boot-persistence-mongodb-4}/src/main/java/com/baeldung/zoneddatetime/config/MongoConfig.java (99%) rename persistence-modules/{spring-boot-persistence-mongodb => spring-boot-persistence-mongodb-4}/src/main/java/com/baeldung/zoneddatetime/converter/ZonedDateTimeReadConverter.java (100%) rename persistence-modules/{spring-boot-persistence-mongodb => spring-boot-persistence-mongodb-4}/src/main/java/com/baeldung/zoneddatetime/converter/ZonedDateTimeWriteConverter.java (100%) rename persistence-modules/{spring-boot-persistence-mongodb => spring-boot-persistence-mongodb-4}/src/main/java/com/baeldung/zoneddatetime/model/Action.java (100%) rename persistence-modules/{spring-boot-persistence-mongodb => spring-boot-persistence-mongodb-4}/src/main/java/com/baeldung/zoneddatetime/repository/ActionRepository.java (99%) create mode 100644 persistence-modules/spring-boot-persistence-mongodb-4/src/main/resources/application.properties rename persistence-modules/{spring-boot-persistence-mongodb => spring-boot-persistence-mongodb-4}/src/test/java/com/baeldung/mongodb/dbref/DbRefIntegrationTest.java (99%) rename persistence-modules/{spring-boot-persistence-mongodb => spring-boot-persistence-mongodb-4}/src/test/java/com/baeldung/zoneddatetime/ActionRepositoryLiveTest.java (99%) create mode 100644 persistence-modules/spring-boot-persistence-mongodb-4/src/test/resources/application.properties diff --git a/persistence-modules/pom.xml b/persistence-modules/pom.xml index 16893b825f..620fbe0825 100644 --- a/persistence-modules/pom.xml +++ b/persistence-modules/pom.xml @@ -69,6 +69,7 @@ spring-boot-persistence-mongodb spring-boot-persistence-mongodb-2 spring-boot-persistence-mongodb-3 + spring-boot-persistence-mongodb-4 spring-data-arangodb spring-data-cassandra-test diff --git a/persistence-modules/spring-boot-persistence-mongodb-4/README.md b/persistence-modules/spring-boot-persistence-mongodb-4/README.md new file mode 100644 index 0000000000..b6922eb10d --- /dev/null +++ b/persistence-modules/spring-boot-persistence-mongodb-4/README.md @@ -0,0 +1,5 @@ +# Relevant Articles + +- [ZonedDateTime with Spring Data MongoDB](https://www.baeldung.com/spring-data-mongodb-zoneddatetime) +- [A Guide to @DBRef in MongoDB](https://www.baeldung.com/spring-mongodb-dbref-annotation) +- More articles: [[<--prev]](../spring-boot-persistence-mongodb-3) diff --git a/persistence-modules/spring-boot-persistence-mongodb-4/pom.xml b/persistence-modules/spring-boot-persistence-mongodb-4/pom.xml new file mode 100644 index 0000000000..ae387c5709 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-mongodb-4/pom.xml @@ -0,0 +1,34 @@ + + + 4.0.0 + spring-boot-persistence-mongodb-4 + spring-boot-persistence-mongodb-4 + This is simple boot application for Spring boot persistence mongodb test + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-data-mongodb + + + de.flapdoodle.embed + de.flapdoodle.embed.mongo + test + + + + \ No newline at end of file diff --git a/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/mongodb/dbref/DbRefApplication.java b/persistence-modules/spring-boot-persistence-mongodb-4/src/main/java/com/baeldung/mongodb/dbref/DbRefApplication.java similarity index 100% rename from persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/mongodb/dbref/DbRefApplication.java rename to persistence-modules/spring-boot-persistence-mongodb-4/src/main/java/com/baeldung/mongodb/dbref/DbRefApplication.java diff --git a/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/mongodb/dbref/DbRefTester.java b/persistence-modules/spring-boot-persistence-mongodb-4/src/main/java/com/baeldung/mongodb/dbref/DbRefTester.java similarity index 99% rename from persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/mongodb/dbref/DbRefTester.java rename to persistence-modules/spring-boot-persistence-mongodb-4/src/main/java/com/baeldung/mongodb/dbref/DbRefTester.java index 58641e1258..b0c6bebd53 100644 --- a/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/mongodb/dbref/DbRefTester.java +++ b/persistence-modules/spring-boot-persistence-mongodb-4/src/main/java/com/baeldung/mongodb/dbref/DbRefTester.java @@ -1,5 +1,6 @@ package com.baeldung.mongodb.dbref; +import com.baeldung.mongodb.dbref.repository.PersonRepository; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -7,8 +8,6 @@ import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.stereotype.Component; -import com.baeldung.mongodb.dbref.repository.PersonRepository; - @Component public class DbRefTester implements ApplicationRunner { diff --git a/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/mongodb/dbref/model/Person.java b/persistence-modules/spring-boot-persistence-mongodb-4/src/main/java/com/baeldung/mongodb/dbref/model/Person.java similarity index 100% rename from persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/mongodb/dbref/model/Person.java rename to persistence-modules/spring-boot-persistence-mongodb-4/src/main/java/com/baeldung/mongodb/dbref/model/Person.java index 7b7826e716..93f372d8ef 100644 --- a/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/mongodb/dbref/model/Person.java +++ b/persistence-modules/spring-boot-persistence-mongodb-4/src/main/java/com/baeldung/mongodb/dbref/model/Person.java @@ -1,11 +1,11 @@ package com.baeldung.mongodb.dbref.model; -import java.util.List; - import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.mapping.DBRef; import org.springframework.data.mongodb.core.mapping.Document; +import java.util.List; + @Document(collection = "Person") public class Person { diff --git a/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/mongodb/dbref/model/Pet.java b/persistence-modules/spring-boot-persistence-mongodb-4/src/main/java/com/baeldung/mongodb/dbref/model/Pet.java similarity index 100% rename from persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/mongodb/dbref/model/Pet.java rename to persistence-modules/spring-boot-persistence-mongodb-4/src/main/java/com/baeldung/mongodb/dbref/model/Pet.java diff --git a/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/mongodb/dbref/repository/PersonRepository.java b/persistence-modules/spring-boot-persistence-mongodb-4/src/main/java/com/baeldung/mongodb/dbref/repository/PersonRepository.java similarity index 99% rename from persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/mongodb/dbref/repository/PersonRepository.java rename to persistence-modules/spring-boot-persistence-mongodb-4/src/main/java/com/baeldung/mongodb/dbref/repository/PersonRepository.java index 2ef5a9dbd6..7eebf8869b 100644 --- a/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/mongodb/dbref/repository/PersonRepository.java +++ b/persistence-modules/spring-boot-persistence-mongodb-4/src/main/java/com/baeldung/mongodb/dbref/repository/PersonRepository.java @@ -1,8 +1,7 @@ package com.baeldung.mongodb.dbref.repository; -import org.springframework.data.mongodb.repository.MongoRepository; - import com.baeldung.mongodb.dbref.model.Person; +import org.springframework.data.mongodb.repository.MongoRepository; public interface PersonRepository extends MongoRepository { diff --git a/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/config/MongoConfig.java b/persistence-modules/spring-boot-persistence-mongodb-4/src/main/java/com/baeldung/zoneddatetime/config/MongoConfig.java similarity index 99% rename from persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/config/MongoConfig.java rename to persistence-modules/spring-boot-persistence-mongodb-4/src/main/java/com/baeldung/zoneddatetime/config/MongoConfig.java index 4eb3872e34..cf2d24c630 100644 --- a/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/config/MongoConfig.java +++ b/persistence-modules/spring-boot-persistence-mongodb-4/src/main/java/com/baeldung/zoneddatetime/config/MongoConfig.java @@ -1,15 +1,14 @@ package com.baeldung.zoneddatetime.config; -import java.util.ArrayList; -import java.util.List; - +import com.baeldung.zoneddatetime.converter.ZonedDateTimeReadConverter; +import com.baeldung.zoneddatetime.converter.ZonedDateTimeWriteConverter; import org.springframework.core.convert.converter.Converter; import org.springframework.data.mongodb.config.AbstractMongoClientConfiguration; import org.springframework.data.mongodb.core.convert.MongoCustomConversions; import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; -import com.baeldung.zoneddatetime.converter.ZonedDateTimeReadConverter; -import com.baeldung.zoneddatetime.converter.ZonedDateTimeWriteConverter; +import java.util.ArrayList; +import java.util.List; @EnableMongoRepositories(basePackages = { "com.baeldung" }) public class MongoConfig extends AbstractMongoClientConfiguration { diff --git a/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/converter/ZonedDateTimeReadConverter.java b/persistence-modules/spring-boot-persistence-mongodb-4/src/main/java/com/baeldung/zoneddatetime/converter/ZonedDateTimeReadConverter.java similarity index 100% rename from persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/converter/ZonedDateTimeReadConverter.java rename to persistence-modules/spring-boot-persistence-mongodb-4/src/main/java/com/baeldung/zoneddatetime/converter/ZonedDateTimeReadConverter.java diff --git a/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/converter/ZonedDateTimeWriteConverter.java b/persistence-modules/spring-boot-persistence-mongodb-4/src/main/java/com/baeldung/zoneddatetime/converter/ZonedDateTimeWriteConverter.java similarity index 100% rename from persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/converter/ZonedDateTimeWriteConverter.java rename to persistence-modules/spring-boot-persistence-mongodb-4/src/main/java/com/baeldung/zoneddatetime/converter/ZonedDateTimeWriteConverter.java diff --git a/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/model/Action.java b/persistence-modules/spring-boot-persistence-mongodb-4/src/main/java/com/baeldung/zoneddatetime/model/Action.java similarity index 100% rename from persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/model/Action.java rename to persistence-modules/spring-boot-persistence-mongodb-4/src/main/java/com/baeldung/zoneddatetime/model/Action.java diff --git a/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/repository/ActionRepository.java b/persistence-modules/spring-boot-persistence-mongodb-4/src/main/java/com/baeldung/zoneddatetime/repository/ActionRepository.java similarity index 99% rename from persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/repository/ActionRepository.java rename to persistence-modules/spring-boot-persistence-mongodb-4/src/main/java/com/baeldung/zoneddatetime/repository/ActionRepository.java index e214c4b3c4..8fc33a6b6e 100644 --- a/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/zoneddatetime/repository/ActionRepository.java +++ b/persistence-modules/spring-boot-persistence-mongodb-4/src/main/java/com/baeldung/zoneddatetime/repository/ActionRepository.java @@ -1,7 +1,6 @@ package com.baeldung.zoneddatetime.repository; +import com.baeldung.zoneddatetime.model.Action; import org.springframework.data.mongodb.repository.MongoRepository; -import com.baeldung.zoneddatetime.model.Action; - public interface ActionRepository extends MongoRepository { } \ No newline at end of file diff --git a/persistence-modules/spring-boot-persistence-mongodb-4/src/main/resources/application.properties b/persistence-modules/spring-boot-persistence-mongodb-4/src/main/resources/application.properties new file mode 100644 index 0000000000..b1c7e18ea3 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-mongodb-4/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.application.name=spring-boot-persistence-mongodb-4 diff --git a/persistence-modules/spring-boot-persistence-mongodb/src/test/java/com/baeldung/mongodb/dbref/DbRefIntegrationTest.java b/persistence-modules/spring-boot-persistence-mongodb-4/src/test/java/com/baeldung/mongodb/dbref/DbRefIntegrationTest.java similarity index 99% rename from persistence-modules/spring-boot-persistence-mongodb/src/test/java/com/baeldung/mongodb/dbref/DbRefIntegrationTest.java rename to persistence-modules/spring-boot-persistence-mongodb-4/src/test/java/com/baeldung/mongodb/dbref/DbRefIntegrationTest.java index c357c0283c..8668bf9404 100644 --- a/persistence-modules/spring-boot-persistence-mongodb/src/test/java/com/baeldung/mongodb/dbref/DbRefIntegrationTest.java +++ b/persistence-modules/spring-boot-persistence-mongodb-4/src/test/java/com/baeldung/mongodb/dbref/DbRefIntegrationTest.java @@ -1,11 +1,11 @@ package com.baeldung.mongodb.dbref; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.util.ArrayList; -import java.util.List; - +import com.baeldung.mongodb.dbref.model.Person; +import com.baeldung.mongodb.dbref.model.Pet; +import com.baeldung.mongodb.dbref.repository.PersonRepository; +import com.mongodb.BasicDBObjectBuilder; +import com.mongodb.DBObject; +import com.mongodb.DBRef; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -14,12 +14,11 @@ import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; -import com.baeldung.mongodb.dbref.model.Person; -import com.baeldung.mongodb.dbref.model.Pet; -import com.baeldung.mongodb.dbref.repository.PersonRepository; -import com.mongodb.BasicDBObjectBuilder; -import com.mongodb.DBObject; -import com.mongodb.DBRef; +import java.util.ArrayList; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; @RunWith(SpringRunner.class) @SpringBootTest diff --git a/persistence-modules/spring-boot-persistence-mongodb/src/test/java/com/baeldung/zoneddatetime/ActionRepositoryLiveTest.java b/persistence-modules/spring-boot-persistence-mongodb-4/src/test/java/com/baeldung/zoneddatetime/ActionRepositoryLiveTest.java similarity index 99% rename from persistence-modules/spring-boot-persistence-mongodb/src/test/java/com/baeldung/zoneddatetime/ActionRepositoryLiveTest.java rename to persistence-modules/spring-boot-persistence-mongodb-4/src/test/java/com/baeldung/zoneddatetime/ActionRepositoryLiveTest.java index 3a241418ca..09ff1d9375 100644 --- a/persistence-modules/spring-boot-persistence-mongodb/src/test/java/com/baeldung/zoneddatetime/ActionRepositoryLiveTest.java +++ b/persistence-modules/spring-boot-persistence-mongodb-4/src/test/java/com/baeldung/zoneddatetime/ActionRepositoryLiveTest.java @@ -1,5 +1,8 @@ package com.baeldung.zoneddatetime; +import com.baeldung.zoneddatetime.config.MongoConfig; +import com.baeldung.zoneddatetime.model.Action; +import com.baeldung.zoneddatetime.repository.ActionRepository; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -10,10 +13,6 @@ import org.springframework.data.mongodb.core.MongoOperations; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.baeldung.zoneddatetime.config.MongoConfig; -import com.baeldung.zoneddatetime.model.Action; -import com.baeldung.zoneddatetime.repository.ActionRepository; - import java.time.ZoneOffset; import java.time.ZonedDateTime; diff --git a/persistence-modules/spring-boot-persistence-mongodb-4/src/test/resources/application.properties b/persistence-modules/spring-boot-persistence-mongodb-4/src/test/resources/application.properties new file mode 100644 index 0000000000..a5b5fb9804 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-mongodb-4/src/test/resources/application.properties @@ -0,0 +1 @@ +spring.mongodb.embedded.version=4.4.9 \ No newline at end of file diff --git a/persistence-modules/spring-boot-persistence-mongodb/README.md b/persistence-modules/spring-boot-persistence-mongodb/README.md index 5453eb0052..867b31c639 100644 --- a/persistence-modules/spring-boot-persistence-mongodb/README.md +++ b/persistence-modules/spring-boot-persistence-mongodb/README.md @@ -4,8 +4,6 @@ - [Spring Boot Integration Testing with Embedded MongoDB](http://www.baeldung.com/spring-boot-embedded-mongodb) - [Upload and Retrieve Files Using MongoDB and Spring Boot](https://www.baeldung.com/spring-boot-mongodb-upload-file) - [GridFS in Spring Data MongoDB](http://www.baeldung.com/spring-data-mongodb-gridfs) -- [ZonedDateTime with Spring Data MongoDB](https://www.baeldung.com/spring-data-mongodb-zoneddatetime) -- [A Guide to @DBRef in MongoDB](https://www.baeldung.com/spring-mongodb-dbref-annotation) - [Import Data to MongoDB From JSON File Using Java](https://www.baeldung.com/java-import-json-mongodb) - [Spring Data MongoDB – Configure Connection](https://www.baeldung.com/spring-data-mongodb-connection) - More articles: [[next-->]](../spring-boot-persistence-mongodb-2)