Blame view

src/main/java/fr/plil/sio/web/mvc/WebAppConfig.java 2.53 KB
aa193b2b   Julien Iguchi-Cartigny   First version
1
2
  package fr.plil.sio.web.mvc;
  
5e965ce4   Julien Iguchi-Cartigny   working version
3
4
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
aa193b2b   Julien Iguchi-Cartigny   First version
5
6
7
8
9
10
11
  import org.springframework.context.MessageSource;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.ComponentScan;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.context.annotation.Scope;
  import org.springframework.context.annotation.ScopedProxyMode;
  import org.springframework.context.support.ResourceBundleMessageSource;
5e965ce4   Julien Iguchi-Cartigny   working version
12
  import org.springframework.web.context.WebApplicationContext;
aa193b2b   Julien Iguchi-Cartigny   First version
13
14
15
  import org.springframework.web.servlet.ViewResolver;
  import org.springframework.web.servlet.config.annotation.EnableWebMvc;
  import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
5e965ce4   Julien Iguchi-Cartigny   working version
16
  import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
aa193b2b   Julien Iguchi-Cartigny   First version
17
  import org.springframework.web.servlet.view.InternalResourceViewResolver;
5e965ce4   Julien Iguchi-Cartigny   working version
18
  import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
aa193b2b   Julien Iguchi-Cartigny   First version
19
  
aa193b2b   Julien Iguchi-Cartigny   First version
20
  @Configuration
5e965ce4   Julien Iguchi-Cartigny   working version
21
22
23
24
25
  @ComponentScan(basePackages = {"fr.plil.sio.web.mvc"},scopedProxy = ScopedProxyMode.TARGET_CLASS)
  @EnableWebMvc
  public class WebAppConfig extends WebMvcConfigurerAdapter {
  
      private static final Logger logger = LoggerFactory.getLogger(WebAppConfig.class);
aa193b2b   Julien Iguchi-Cartigny   First version
26
27
  
      @Bean
5e965ce4   Julien Iguchi-Cartigny   working version
28
      @Scope(value = WebApplicationContext.SCOPE_SESSION, proxyMode = ScopedProxyMode. TARGET_CLASS)
aa193b2b   Julien Iguchi-Cartigny   First version
29
      public UserSession userSession() {
d938bbff   Julien Iguchi-Cartigny   add log message
30
          logger.debug("new user session bean");
aa193b2b   Julien Iguchi-Cartigny   First version
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
          return new UserSession();
      }
  
      @Bean
      public CheckUserInterceptor checkUserInterceptor() {
          return new CheckUserInterceptor();
      }
  
      @Override
      public void addInterceptors(InterceptorRegistry registry) {
          CheckUserInterceptor interceptor = checkUserInterceptor();
          interceptor.setUserSession(userSession());
          registry.addInterceptor(interceptor);
      }
  
      @Bean
      public MessageSource messageSource() {
          ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
          messageSource.setBasename("messages");
5e965ce4   Julien Iguchi-Cartigny   working version
50
          messageSource.setDefaultEncoding("UTF-8");
aa193b2b   Julien Iguchi-Cartigny   First version
51
52
53
54
55
56
          return messageSource;
      }
  
      @Bean
      public ViewResolver viewResolver() {
          InternalResourceViewResolver resolver = new InternalResourceViewResolver();
5e965ce4   Julien Iguchi-Cartigny   working version
57
          resolver.setPrefix("/WEB-INF/views/");
aa193b2b   Julien Iguchi-Cartigny   First version
58
59
60
61
          resolver.setSuffix(".jsp");
          return resolver;
      }
  
5e965ce4   Julien Iguchi-Cartigny   working version
62
63
64
65
      @Override
      public void addResourceHandlers(ResourceHandlerRegistry registry) {
          registry.addResourceHandler("/resources/").addResourceLocations("/resources/**");
      }
aa193b2b   Julien Iguchi-Cartigny   First version
66
  }