Blame view

src/main/java/com/daeucna/board/config/WebMvcConfig.java 4.61 KB
a6468920   sangkiham   Spring Boot Board...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
100
101
102
103
104
105
106
107
108
109
110
111
  package com.daeucna.board.config;

   

  import org.springframework.beans.factory.annotation.Value;

  import org.springframework.context.annotation.Bean;

  import org.springframework.context.annotation.ComponentScan;

  import org.springframework.context.annotation.ComponentScan.Filter;

  import org.springframework.context.annotation.Configuration;

  import org.springframework.context.annotation.FilterType;

  import org.springframework.http.MediaType;

  import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;

  import org.springframework.http.converter.xml.MarshallingHttpMessageConverter;

  import org.springframework.jdbc.datasource.DataSourceTransactionManager;

  import org.springframework.oxm.jaxb.Jaxb2Marshaller;

  import org.springframework.stereotype.Component;

  import org.springframework.stereotype.Controller;

  import org.springframework.stereotype.Repository;

  import org.springframework.stereotype.Service;

  import org.springframework.transaction.PlatformTransactionManager;

  import org.springframework.web.bind.annotation.ControllerAdvice;

  import org.springframework.web.multipart.commons.CommonsMultipartResolver;

  import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;

  import org.springframework.web.servlet.config.annotation.InterceptorRegistry;

  import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;

  import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;

  import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;

  import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

  import org.springframework.web.servlet.view.BeanNameViewResolver;

  

  import com.daeucna.board.common.FileDownloadUtil;

  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);

      }    

  }