From a0cbfa3b061a11832c710c83e13a85a5af48d550 Mon Sep 17 00:00:00 2001 From: wugangca Date: Fri, 4 Oct 2019 06:30:54 -0600 Subject: [PATCH] =?UTF-8?q?BAEL-2988=20Move=20the=20code=20from=20spring-r?= =?UTF-8?q?est-simple=20to=20spring-mvc-simple-=E2=80=A6=20(#7914)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * BAEL-2988 Move the code from spring-rest-simple to spring-mvc-simple-2, based on the review feedback. * BAEL-2988 revert previous changes in the spring-rest-simple --- .../com/baeldung/spring/config/MvcConfig.java | 22 +++++++++++++++++++ .../converter/StringToEnumConverter.java | 4 ++-- .../spring/enums}/EnumController.java | 6 ++--- .../GlobalControllerExceptionHandler.java | 2 +- .../com/baeldung/spring}/model/Modes.java | 2 +- .../java/com/baeldung/config/MvcConfig.java | 7 ------ 6 files changed, 28 insertions(+), 15 deletions(-) create mode 100644 spring-mvc-simple-2/src/main/java/com/baeldung/spring/config/MvcConfig.java rename {spring-rest-simple/src/main/java/com/baeldung => spring-mvc-simple-2/src/main/java/com/baeldung/spring}/config/converter/StringToEnumConverter.java (86%) rename {spring-rest-simple/src/main/java/com/baeldung/cors => spring-mvc-simple-2/src/main/java/com/baeldung/spring/enums}/EnumController.java (81%) rename {spring-rest-simple/src/main/java/com/baeldung => spring-mvc-simple-2/src/main/java/com/baeldung/spring}/exceptions/GlobalControllerExceptionHandler.java (94%) rename {spring-rest-simple/src/main/java/com/baeldung => spring-mvc-simple-2/src/main/java/com/baeldung/spring}/model/Modes.java (53%) diff --git a/spring-mvc-simple-2/src/main/java/com/baeldung/spring/config/MvcConfig.java b/spring-mvc-simple-2/src/main/java/com/baeldung/spring/config/MvcConfig.java new file mode 100644 index 0000000000..ad99e8169b --- /dev/null +++ b/spring-mvc-simple-2/src/main/java/com/baeldung/spring/config/MvcConfig.java @@ -0,0 +1,22 @@ +package com.baeldung.spring.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.format.FormatterRegistry; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +import com.baeldung.spring.config.converter.StringToEnumConverter; + +@Configuration +@EnableWebMvc +public class MvcConfig implements WebMvcConfigurer { + + public MvcConfig() { + super(); + } + + @Override + public void addFormatters(FormatterRegistry registry) { + registry.addConverter(new StringToEnumConverter()); + } +} diff --git a/spring-rest-simple/src/main/java/com/baeldung/config/converter/StringToEnumConverter.java b/spring-mvc-simple-2/src/main/java/com/baeldung/spring/config/converter/StringToEnumConverter.java similarity index 86% rename from spring-rest-simple/src/main/java/com/baeldung/config/converter/StringToEnumConverter.java rename to spring-mvc-simple-2/src/main/java/com/baeldung/spring/config/converter/StringToEnumConverter.java index 349ee5a796..b481f691bf 100644 --- a/spring-rest-simple/src/main/java/com/baeldung/config/converter/StringToEnumConverter.java +++ b/spring-mvc-simple-2/src/main/java/com/baeldung/spring/config/converter/StringToEnumConverter.java @@ -1,9 +1,9 @@ -package com.baeldung.config.converter; +package com.baeldung.spring.config.converter; import org.springframework.core.convert.converter.Converter; import org.springframework.stereotype.Component; -import com.baeldung.model.Modes; +import com.baeldung.spring.model.Modes; @Component public class StringToEnumConverter implements Converter { diff --git a/spring-rest-simple/src/main/java/com/baeldung/cors/EnumController.java b/spring-mvc-simple-2/src/main/java/com/baeldung/spring/enums/EnumController.java similarity index 81% rename from spring-rest-simple/src/main/java/com/baeldung/cors/EnumController.java rename to spring-mvc-simple-2/src/main/java/com/baeldung/spring/enums/EnumController.java index 34ce4d3927..356e751d5e 100644 --- a/spring-rest-simple/src/main/java/com/baeldung/cors/EnumController.java +++ b/spring-mvc-simple-2/src/main/java/com/baeldung/spring/enums/EnumController.java @@ -1,15 +1,13 @@ -package com.baeldung.cors; +package com.baeldung.spring.enums; -import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import com.baeldung.model.Modes; +import com.baeldung.spring.model.Modes; -@CrossOrigin(maxAge = 3600) @RestController @RequestMapping("/enums") public class EnumController { diff --git a/spring-rest-simple/src/main/java/com/baeldung/exceptions/GlobalControllerExceptionHandler.java b/spring-mvc-simple-2/src/main/java/com/baeldung/spring/exceptions/GlobalControllerExceptionHandler.java similarity index 94% rename from spring-rest-simple/src/main/java/com/baeldung/exceptions/GlobalControllerExceptionHandler.java rename to spring-mvc-simple-2/src/main/java/com/baeldung/spring/exceptions/GlobalControllerExceptionHandler.java index 78fbcf97dd..2e0f1b6559 100644 --- a/spring-rest-simple/src/main/java/com/baeldung/exceptions/GlobalControllerExceptionHandler.java +++ b/spring-mvc-simple-2/src/main/java/com/baeldung/spring/exceptions/GlobalControllerExceptionHandler.java @@ -1,4 +1,4 @@ -package com.baeldung.exceptions; +package com.baeldung.spring.exceptions; import org.springframework.core.convert.ConversionFailedException; import org.springframework.http.HttpStatus; diff --git a/spring-rest-simple/src/main/java/com/baeldung/model/Modes.java b/spring-mvc-simple-2/src/main/java/com/baeldung/spring/model/Modes.java similarity index 53% rename from spring-rest-simple/src/main/java/com/baeldung/model/Modes.java rename to spring-mvc-simple-2/src/main/java/com/baeldung/spring/model/Modes.java index d3a1ab4a61..dc05448f3f 100644 --- a/spring-rest-simple/src/main/java/com/baeldung/model/Modes.java +++ b/spring-mvc-simple-2/src/main/java/com/baeldung/spring/model/Modes.java @@ -1,4 +1,4 @@ -package com.baeldung.model; +package com.baeldung.spring.model; public enum Modes { ALPHA, BETA; diff --git a/spring-rest-simple/src/main/java/com/baeldung/config/MvcConfig.java b/spring-rest-simple/src/main/java/com/baeldung/config/MvcConfig.java index 246049b722..48b627a344 100644 --- a/spring-rest-simple/src/main/java/com/baeldung/config/MvcConfig.java +++ b/spring-rest-simple/src/main/java/com/baeldung/config/MvcConfig.java @@ -2,7 +2,6 @@ package com.baeldung.config; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; -import org.springframework.format.FormatterRegistry; import org.springframework.http.MediaType; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.StringHttpMessageConverter; @@ -18,7 +17,6 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import com.baeldung.config.converter.KryoHttpMessageConverter; -import com.baeldung.config.converter.StringToEnumConverter; import java.text.SimpleDateFormat; import java.util.List; @@ -73,9 +71,4 @@ public class MvcConfig implements WebMvcConfigurer { public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**"); } - - @Override - public void addFormatters(FormatterRegistry registry) { - registry.addConverter(new StringToEnumConverter()); - } }