File tree Expand file tree Collapse file tree 6 files changed +28
-15
lines changed
spring-mvc-simple-2/src/main/java/com/baeldung/spring
spring-rest-simple/src/main/java/com/baeldung/config Expand file tree Collapse file tree 6 files changed +28
-15
lines changed Original file line number Diff line number Diff line change
1
+ package com .baeldung .spring .config ;
2
+
3
+ import org .springframework .context .annotation .Configuration ;
4
+ import org .springframework .format .FormatterRegistry ;
5
+ import org .springframework .web .servlet .config .annotation .EnableWebMvc ;
6
+ import org .springframework .web .servlet .config .annotation .WebMvcConfigurer ;
7
+
8
+ import com .baeldung .spring .config .converter .StringToEnumConverter ;
9
+
10
+ @ Configuration
11
+ @ EnableWebMvc
12
+ public class MvcConfig implements WebMvcConfigurer {
13
+
14
+ public MvcConfig () {
15
+ super ();
16
+ }
17
+
18
+ @ Override
19
+ public void addFormatters (FormatterRegistry registry ) {
20
+ registry .addConverter (new StringToEnumConverter ());
21
+ }
22
+ }
Original file line number Diff line number Diff line change 1
- package com .baeldung .config .converter ;
1
+ package com .baeldung .spring . config .converter ;
2
2
3
3
import org .springframework .core .convert .converter .Converter ;
4
4
import org .springframework .stereotype .Component ;
5
5
6
- import com .baeldung .model .Modes ;
6
+ import com .baeldung .spring . model .Modes ;
7
7
8
8
@ Component
9
9
public class StringToEnumConverter implements Converter <String , Modes > {
Original file line number Diff line number Diff line change 1
- package com .baeldung .cors ;
1
+ package com .baeldung .spring . enums ;
2
2
3
- import org .springframework .web .bind .annotation .CrossOrigin ;
4
3
import org .springframework .web .bind .annotation .GetMapping ;
5
4
import org .springframework .web .bind .annotation .PathVariable ;
6
5
import org .springframework .web .bind .annotation .RequestMapping ;
7
6
import org .springframework .web .bind .annotation .RequestParam ;
8
7
import org .springframework .web .bind .annotation .RestController ;
9
8
10
- import com .baeldung .model .Modes ;
9
+ import com .baeldung .spring . model .Modes ;
11
10
12
- @ CrossOrigin (maxAge = 3600 )
13
11
@ RestController
14
12
@ RequestMapping ("/enums" )
15
13
public class EnumController {
Original file line number Diff line number Diff line change 1
- package com .baeldung .exceptions ;
1
+ package com .baeldung .spring . exceptions ;
2
2
3
3
import org .springframework .core .convert .ConversionFailedException ;
4
4
import org .springframework .http .HttpStatus ;
Original file line number Diff line number Diff line change 1
- package com .baeldung .model ;
1
+ package com .baeldung .spring . model ;
2
2
3
3
public enum Modes {
4
4
ALPHA , BETA ;
Original file line number Diff line number Diff line change 2
2
3
3
import org .springframework .context .annotation .ComponentScan ;
4
4
import org .springframework .context .annotation .Configuration ;
5
- import org .springframework .format .FormatterRegistry ;
6
5
import org .springframework .http .MediaType ;
7
6
import org .springframework .http .converter .HttpMessageConverter ;
8
7
import org .springframework .http .converter .StringHttpMessageConverter ;
18
17
import org .springframework .web .servlet .config .annotation .WebMvcConfigurer ;
19
18
20
19
import com .baeldung .config .converter .KryoHttpMessageConverter ;
21
- import com .baeldung .config .converter .StringToEnumConverter ;
22
20
23
21
import java .text .SimpleDateFormat ;
24
22
import java .util .List ;
@@ -73,9 +71,4 @@ public void configureContentNegotiation(ContentNegotiationConfigurer configurer)
73
71
public void addCorsMappings (CorsRegistry registry ) {
74
72
registry .addMapping ("/**" );
75
73
}
76
-
77
- @ Override
78
- public void addFormatters (FormatterRegistry registry ) {
79
- registry .addConverter (new StringToEnumConverter ());
80
- }
81
74
}
You can’t perform that action at this time.
0 commit comments