From 789c6695df43af2f9dd76ec3bc9840aa87dc3c85 Mon Sep 17 00:00:00 2001 From: amit2103 Date: Sun, 14 Apr 2019 00:49:30 +0530 Subject: [PATCH 1/2] [BAEL-14089] - Moved code for Entity to DTO article --- spring-boot-rest/pom.xml | 6 ++++++ .../main/java/com/baeldung/SpringBootRestApplication.java | 2 +- .../java/com/baeldung/modelmapper/PostApplication.java | 0 .../modelmapper/controller/PostRestController.java | 0 .../main/java/com/baeldung/modelmapper/dto/PostDto.java | 0 .../main/java/com/baeldung/modelmapper/dto/UserDto.java | 0 .../src/main/java/com/baeldung/modelmapper/model/Post.java | 0 .../java/com/baeldung/modelmapper/model/Preference.java | 0 .../src/main/java/com/baeldung/modelmapper/model/User.java | 0 .../baeldung/modelmapper/repository/PostRepository.java | 0 .../com/baeldung/modelmapper/service/IPostService.java | 0 .../com/baeldung/modelmapper/service/IUserService.java | 0 .../java/com/baeldung/modelmapper/service/PostService.java | 0 .../java/com/baeldung/modelmapper/service/UserService.java | 0 .../java/com/baeldung/SpringContextIntegrationTest.java | 2 +- .../java/com/baeldung/modelmapper/PostDtoUnitTest.java | 0 spring-boot/pom.xml | 7 ------- 17 files changed, 8 insertions(+), 9 deletions(-) rename {spring-boot => spring-boot-rest}/src/main/java/com/baeldung/modelmapper/PostApplication.java (100%) rename {spring-boot => spring-boot-rest}/src/main/java/com/baeldung/modelmapper/controller/PostRestController.java (100%) rename {spring-boot => spring-boot-rest}/src/main/java/com/baeldung/modelmapper/dto/PostDto.java (100%) rename {spring-boot => spring-boot-rest}/src/main/java/com/baeldung/modelmapper/dto/UserDto.java (100%) rename {spring-boot => spring-boot-rest}/src/main/java/com/baeldung/modelmapper/model/Post.java (100%) rename {spring-boot => spring-boot-rest}/src/main/java/com/baeldung/modelmapper/model/Preference.java (100%) rename {spring-boot => spring-boot-rest}/src/main/java/com/baeldung/modelmapper/model/User.java (100%) rename {spring-boot => spring-boot-rest}/src/main/java/com/baeldung/modelmapper/repository/PostRepository.java (100%) rename {spring-boot => spring-boot-rest}/src/main/java/com/baeldung/modelmapper/service/IPostService.java (100%) rename {spring-boot => spring-boot-rest}/src/main/java/com/baeldung/modelmapper/service/IUserService.java (100%) rename {spring-boot => spring-boot-rest}/src/main/java/com/baeldung/modelmapper/service/PostService.java (100%) rename {spring-boot => spring-boot-rest}/src/main/java/com/baeldung/modelmapper/service/UserService.java (100%) rename {spring-boot => spring-boot-rest}/src/test/java/com/baeldung/modelmapper/PostDtoUnitTest.java (100%) diff --git a/spring-boot-rest/pom.xml b/spring-boot-rest/pom.xml index decaccd148..a7ba67d92a 100644 --- a/spring-boot-rest/pom.xml +++ b/spring-boot-rest/pom.xml @@ -63,6 +63,11 @@ htmlunit test + + org.modelmapper + modelmapper + ${modelmapper.version} + @@ -78,5 +83,6 @@ com.baeldung.SpringBootRestApplication 27.0.1-jre 1.4.11.1 + 2.3.2 diff --git a/spring-boot-rest/src/main/java/com/baeldung/SpringBootRestApplication.java b/spring-boot-rest/src/main/java/com/baeldung/SpringBootRestApplication.java index 62aae7619d..d0976d9ddd 100644 --- a/spring-boot-rest/src/main/java/com/baeldung/SpringBootRestApplication.java +++ b/spring-boot-rest/src/main/java/com/baeldung/SpringBootRestApplication.java @@ -3,7 +3,7 @@ package com.baeldung; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -@SpringBootApplication +@SpringBootApplication(scanBasePackages = {"com.baeldung.persistence", "com.baeldung.spring", "com.baeldung.web" }) public class SpringBootRestApplication { public static void main(String[] args) { diff --git a/spring-boot/src/main/java/com/baeldung/modelmapper/PostApplication.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/PostApplication.java similarity index 100% rename from spring-boot/src/main/java/com/baeldung/modelmapper/PostApplication.java rename to spring-boot-rest/src/main/java/com/baeldung/modelmapper/PostApplication.java diff --git a/spring-boot/src/main/java/com/baeldung/modelmapper/controller/PostRestController.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/controller/PostRestController.java similarity index 100% rename from spring-boot/src/main/java/com/baeldung/modelmapper/controller/PostRestController.java rename to spring-boot-rest/src/main/java/com/baeldung/modelmapper/controller/PostRestController.java diff --git a/spring-boot/src/main/java/com/baeldung/modelmapper/dto/PostDto.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/dto/PostDto.java similarity index 100% rename from spring-boot/src/main/java/com/baeldung/modelmapper/dto/PostDto.java rename to spring-boot-rest/src/main/java/com/baeldung/modelmapper/dto/PostDto.java diff --git a/spring-boot/src/main/java/com/baeldung/modelmapper/dto/UserDto.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/dto/UserDto.java similarity index 100% rename from spring-boot/src/main/java/com/baeldung/modelmapper/dto/UserDto.java rename to spring-boot-rest/src/main/java/com/baeldung/modelmapper/dto/UserDto.java diff --git a/spring-boot/src/main/java/com/baeldung/modelmapper/model/Post.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/model/Post.java similarity index 100% rename from spring-boot/src/main/java/com/baeldung/modelmapper/model/Post.java rename to spring-boot-rest/src/main/java/com/baeldung/modelmapper/model/Post.java diff --git a/spring-boot/src/main/java/com/baeldung/modelmapper/model/Preference.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/model/Preference.java similarity index 100% rename from spring-boot/src/main/java/com/baeldung/modelmapper/model/Preference.java rename to spring-boot-rest/src/main/java/com/baeldung/modelmapper/model/Preference.java diff --git a/spring-boot/src/main/java/com/baeldung/modelmapper/model/User.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/model/User.java similarity index 100% rename from spring-boot/src/main/java/com/baeldung/modelmapper/model/User.java rename to spring-boot-rest/src/main/java/com/baeldung/modelmapper/model/User.java diff --git a/spring-boot/src/main/java/com/baeldung/modelmapper/repository/PostRepository.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/repository/PostRepository.java similarity index 100% rename from spring-boot/src/main/java/com/baeldung/modelmapper/repository/PostRepository.java rename to spring-boot-rest/src/main/java/com/baeldung/modelmapper/repository/PostRepository.java diff --git a/spring-boot/src/main/java/com/baeldung/modelmapper/service/IPostService.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/service/IPostService.java similarity index 100% rename from spring-boot/src/main/java/com/baeldung/modelmapper/service/IPostService.java rename to spring-boot-rest/src/main/java/com/baeldung/modelmapper/service/IPostService.java diff --git a/spring-boot/src/main/java/com/baeldung/modelmapper/service/IUserService.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/service/IUserService.java similarity index 100% rename from spring-boot/src/main/java/com/baeldung/modelmapper/service/IUserService.java rename to spring-boot-rest/src/main/java/com/baeldung/modelmapper/service/IUserService.java diff --git a/spring-boot/src/main/java/com/baeldung/modelmapper/service/PostService.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/service/PostService.java similarity index 100% rename from spring-boot/src/main/java/com/baeldung/modelmapper/service/PostService.java rename to spring-boot-rest/src/main/java/com/baeldung/modelmapper/service/PostService.java diff --git a/spring-boot/src/main/java/com/baeldung/modelmapper/service/UserService.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/service/UserService.java similarity index 100% rename from spring-boot/src/main/java/com/baeldung/modelmapper/service/UserService.java rename to spring-boot-rest/src/main/java/com/baeldung/modelmapper/service/UserService.java diff --git a/spring-boot-rest/src/test/java/com/baeldung/SpringContextIntegrationTest.java b/spring-boot-rest/src/test/java/com/baeldung/SpringContextIntegrationTest.java index 25fbc4cc02..3db1ecb462 100644 --- a/spring-boot-rest/src/test/java/com/baeldung/SpringContextIntegrationTest.java +++ b/spring-boot-rest/src/test/java/com/baeldung/SpringContextIntegrationTest.java @@ -6,7 +6,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) -@SpringBootTest +@SpringBootTest(classes = {SpringBootRestApplication.class}) public class SpringContextIntegrationTest { @Test diff --git a/spring-boot/src/test/java/com/baeldung/modelmapper/PostDtoUnitTest.java b/spring-boot-rest/src/test/java/com/baeldung/modelmapper/PostDtoUnitTest.java similarity index 100% rename from spring-boot/src/test/java/com/baeldung/modelmapper/PostDtoUnitTest.java rename to spring-boot-rest/src/test/java/com/baeldung/modelmapper/PostDtoUnitTest.java diff --git a/spring-boot/pom.xml b/spring-boot/pom.xml index ed2d8259df..401e0289e8 100644 --- a/spring-boot/pom.xml +++ b/spring-boot/pom.xml @@ -153,12 +153,6 @@ javax.validation validation-api - - - org.modelmapper - modelmapper - ${modelmapper.version} - @@ -256,7 +250,6 @@ 5.2.4 18.0 2.2.4 - 2.3.2 From 4d5d647e712f105151e9c58326ea7132e80a7bed Mon Sep 17 00:00:00 2001 From: amit2103 Date: Sun, 14 Apr 2019 23:34:23 +0530 Subject: [PATCH 2/2] [BAEL-14089] - Removed PostRestApplication main class and adjusted configuration --- spring-boot-rest/pom.xml | 2 +- .../baeldung/SpringBootRestApplication.java | 9 ++++++++- .../baeldung/modelmapper/PostApplication.java | 20 ------------------- .../baeldung/spring/PersistenceConfig.java | 6 +++--- 4 files changed, 12 insertions(+), 25 deletions(-) delete mode 100644 spring-boot-rest/src/main/java/com/baeldung/modelmapper/PostApplication.java diff --git a/spring-boot-rest/pom.xml b/spring-boot-rest/pom.xml index a7ba67d92a..2bf7c0181f 100644 --- a/spring-boot-rest/pom.xml +++ b/spring-boot-rest/pom.xml @@ -83,6 +83,6 @@ com.baeldung.SpringBootRestApplication 27.0.1-jre 1.4.11.1 - 2.3.2 + 2.3.3 diff --git a/spring-boot-rest/src/main/java/com/baeldung/SpringBootRestApplication.java b/spring-boot-rest/src/main/java/com/baeldung/SpringBootRestApplication.java index d0976d9ddd..1c0d0d19e8 100644 --- a/spring-boot-rest/src/main/java/com/baeldung/SpringBootRestApplication.java +++ b/spring-boot-rest/src/main/java/com/baeldung/SpringBootRestApplication.java @@ -1,13 +1,20 @@ package com.baeldung; +import org.modelmapper.ModelMapper; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; -@SpringBootApplication(scanBasePackages = {"com.baeldung.persistence", "com.baeldung.spring", "com.baeldung.web" }) +@SpringBootApplication public class SpringBootRestApplication { public static void main(String[] args) { SpringApplication.run(SpringBootRestApplication.class, args); } + + @Bean + public ModelMapper modelMapper() { + return new ModelMapper(); + } } diff --git a/spring-boot-rest/src/main/java/com/baeldung/modelmapper/PostApplication.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/PostApplication.java deleted file mode 100644 index 7684c43648..0000000000 --- a/spring-boot-rest/src/main/java/com/baeldung/modelmapper/PostApplication.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.baeldung.modelmapper; - -import org.modelmapper.ModelMapper; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; - -@SpringBootApplication -public class PostApplication { - - public static void main(String[] args) { - SpringApplication.run(PostApplication.class, args); - } - - @Bean - public ModelMapper modelMapper() { - return new ModelMapper(); - } - -} diff --git a/spring-boot-rest/src/main/java/com/baeldung/spring/PersistenceConfig.java b/spring-boot-rest/src/main/java/com/baeldung/spring/PersistenceConfig.java index 5179c66978..2e967751ad 100644 --- a/spring-boot-rest/src/main/java/com/baeldung/spring/PersistenceConfig.java +++ b/spring-boot-rest/src/main/java/com/baeldung/spring/PersistenceConfig.java @@ -24,8 +24,8 @@ import com.google.common.base.Preconditions; @Configuration @EnableTransactionManagement @PropertySource({ "classpath:persistence-${envTarget:h2}.properties" }) -@ComponentScan({ "com.baeldung.persistence" }) -@EnableJpaRepositories(basePackages = "com.baeldung.persistence.dao") +@ComponentScan(basePackages = { "com.baeldung.persistence", "com.baeldung.modelmapper" }) +@EnableJpaRepositories(basePackages = {"com.baeldung.persistence.dao", "com.baeldung.modelmapper.repository"}) public class PersistenceConfig { @Autowired @@ -39,7 +39,7 @@ public class PersistenceConfig { public LocalContainerEntityManagerFactoryBean entityManagerFactory() { final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); em.setDataSource(dataSource()); - em.setPackagesToScan(new String[] { "com.baeldung.persistence.model" }); + em.setPackagesToScan(new String[] { "com.baeldung.persistence.model", "com.baeldung.modelmapper.model" }); final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); // vendorAdapter.set