Rev 26192 | Rev 26194 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.spice.profitmandi.web.config;import java.time.LocalDateTime;import java.time.chrono.IsoChronology;import java.time.format.DateTimeFormatter;import java.time.format.DateTimeFormatterBuilder;import java.time.format.ResolverStyle;import java.util.List;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.context.annotation.Bean;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.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.datatype.jdk8.Jdk8Module;import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;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()registry.addInterceptor(authenticationInterceptor).addPathPatterns("/**").excludePathPatterns("/hdfctest/**", "/hdfc/**","/login", "/login/","/forgetPassword","/forgetPassword/", "/", "/checkplans", "/12dashboard34");registry.addInterceptor(roleInterceptor).excludePathPatterns("/hdfctest/**", "/hdfc/**","/login", "/login/", "/register", "/register/","/forgetPassword","/forgetPassword/", "/","", "/12dashboard34");}@Overridepublic void addFormatters(FormatterRegistry registry) {DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();DateTimeFormatter df = new DateTimeFormatterBuilder().parseCaseInsensitive().append(DateTimeFormatter.ISO_LOCAL_DATE).appendLiteral('T').append(DateTimeFormatter.ISO_LOCAL_TIME).toFormatter();registrar.setDateTimeFormatter(df);registrar.setDateFormatter(DateTimeFormatter.ISO_LOCAL_DATE);registrar.setTimeFormatter(DateTimeFormatter.ISO_LOCAL_TIME);registrar.registerFormatters(registry);}@Overridepublic void extendMessageConverters(List<HttpMessageConverter<?>> converters) {converters.add(new MappingJackson2HttpMessageConverter(objectMapper()));}@Beanpublic ObjectMapper objectMapper() {DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd[[T][ ]]HH:mm:ss");DateTimeFormatter sf = new DateTimeFormatterBuilder().parseCaseInsensitive().append(DateTimeFormatter.ISO_LOCAL_DATE).appendLiteral('T').append(DateTimeFormatter.ISO_LOCAL_TIME).toFormatter();LocalDateTimeSerializer serializer = new LocalDateTimeSerializer(sf);LocalDateTimeDeserializer deserializer = new LocalDateTimeDeserializer(df);JavaTimeModule jtm = new JavaTimeModule();jtm.addSerializer(LocalDateTime.class, serializer);jtm.addDeserializer(LocalDateTime.class, deserializer);ObjectMapper mapper = new ObjectMapper().registerModule(new ParameterNamesModule()).registerModule(new Jdk8Module()).registerModule(jtm); // new module, NOT JSR310Modulereturn mapper;}}