Rev 23924 | Rev 23951 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.spice.profitmandi.web.config;import java.util.List;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.context.annotation.ComponentScan;import org.springframework.context.annotation.Configuration;import org.springframework.format.FormatterRegistry;import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar;import org.springframework.http.converter.HttpMessageConverter;import org.springframework.http.converter.ResourceHttpMessageConverter;import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;import org.springframework.web.servlet.config.annotation.EnableWebMvc;import org.springframework.web.servlet.config.annotation.InterceptorRegistry;import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;import com.fasterxml.jackson.databind.ObjectMapper;import com.fasterxml.jackson.databind.SerializationFeature;import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;import com.spice.profitmandi.web.interceptor.AuthenticationInterceptor;import com.spice.profitmandi.web.interceptor.RoleInterceptor;@EnableWebMvc@Configuration@ComponentScan({"com.spice.profitmandi.*"})public class WebConfig extends WebMvcConfigurerAdapter{private static final String RESOURCES_PATTERN="/resources/**";private static final String RESOURCES_LOCATION="/resources/";@AutowiredAuthenticationInterceptor authenticationInterceptor;@AutowiredRoleInterceptor roleInterceptor;@Overridepublic void addResourceHandlers(ResourceHandlerRegistry registry) {registry.addResourceHandler(RESOURCES_PATTERN).addResourceLocations(RESOURCES_LOCATION);}@Overridepublic void addInterceptors(InterceptorRegistry registry) {registry.addInterceptor(authenticationInterceptor).addPathPatterns("/**").excludePathPatterns("/login", "/login/", "/", "");registry.addInterceptor(roleInterceptor).excludePathPatterns("/login", "/login/", "/register", "/register/", "", "/");}@Overridepublic void addFormatters(FormatterRegistry registry) {DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();registrar.setUseIsoFormat(true);registrar.registerFormatters(registry);}@Overridepublic void extendMessageConverters(List<HttpMessageConverter<?>> converters) {converters.add(new MappingJackson2HttpMessageConverter(objectMapper()));}private ObjectMapper objectMapper() {ObjectMapper mapper = new ObjectMapper().registerModule(new ParameterNamesModule()).registerModule(new Jdk8Module()).registerModule(new JavaTimeModule()); // new module, NOT JSR310Modulereturn mapper;}}