a6468920
sangkiham
Spring Boot Board...
|
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
import com.daeucna.board.interceptor.BaseInterceptor;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;
@ComponentScan(
basePackages = "com.daeucna",
useDefaultFilters = false,
includeFilters = {
@Filter(
type = FilterType.REGEX,
pattern = {".*Controller.*"}
)
}
)
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Value("${spring.webservice.intro}")
private String introPage;
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new BaseInterceptor())
.addPathPatterns("/**")
.excludePathPatterns("/sample/**");
}
@Bean
public MappingJackson2HttpMessageConverter mappingJacksonHttpMessageConverter() {
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
ObjectMapper objectMapper = converter.getObjectMapper();
objectMapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
objectMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
JaxbAnnotationModule module = new JaxbAnnotationModule();
objectMapper.registerModule(module);
return converter;
}
@Bean
public MarshallingHttpMessageConverter marshallingHttpMessageConverter() {
MarshallingHttpMessageConverter converter = new MarshallingHttpMessageConverter();
converter.setMarshaller(jaxb2Marshaller());
converter.setUnmarshaller(jaxb2Marshaller());
return converter;
}
@Bean
public Jaxb2Marshaller jaxb2Marshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setPackagesToScan(new String[] { "com.daeucna.board.security.domain", "com.daeucna.board.domain" });
return marshaller;
}
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.favorParameter(true)
.ignoreAcceptHeader(false)
.defaultContentType(MediaType.APPLICATION_JSON)
.mediaType("json", MediaType.APPLICATION_JSON)
.mediaType("xml", MediaType.APPLICATION_XML);
}
//jsp엔진 추가시 thymeleaf엔진은 제외해야함
/*
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
registry.jsp("/jsp/", ".jsp");
}
*/
@Override
public void addViewControllers(ViewControllerRegistry registry) {
// 루트 (/) 로 접근 시 introPage로 이동하는 매핑 추가
registry.addRedirectViewController("/", introPage);
}
}
|