| 21561 |
ashik.ali |
1 |
package com.spice.profitmandi.web.config;
|
| 21555 |
kshitij.so |
2 |
|
| 23878 |
amit.gupta |
3 |
import java.util.List;
|
|
|
4 |
|
| 21561 |
ashik.ali |
5 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 21555 |
kshitij.so |
6 |
import org.springframework.context.annotation.ComponentScan;
|
|
|
7 |
import org.springframework.context.annotation.Configuration;
|
| 23886 |
amit.gupta |
8 |
import org.springframework.format.FormatterRegistry;
|
|
|
9 |
import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar;
|
| 23924 |
amit.gupta |
10 |
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
|
| 23878 |
amit.gupta |
11 |
import org.springframework.http.converter.HttpMessageConverter;
|
| 23890 |
amit.gupta |
12 |
import org.springframework.http.converter.ResourceHttpMessageConverter;
|
| 23878 |
amit.gupta |
13 |
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
| 21555 |
kshitij.so |
14 |
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
| 21561 |
ashik.ali |
15 |
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
| 21555 |
kshitij.so |
16 |
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
|
|
17 |
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
|
|
18 |
|
| 23878 |
amit.gupta |
19 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
| 23890 |
amit.gupta |
20 |
import com.fasterxml.jackson.databind.SerializationFeature;
|
| 23878 |
amit.gupta |
21 |
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
|
|
|
22 |
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
|
|
23 |
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
|
| 21561 |
ashik.ali |
24 |
import com.spice.profitmandi.web.interceptor.AuthenticationInterceptor;
|
| 22107 |
ashik.ali |
25 |
import com.spice.profitmandi.web.interceptor.RoleInterceptor;
|
| 21561 |
ashik.ali |
26 |
|
| 21555 |
kshitij.so |
27 |
@EnableWebMvc
|
|
|
28 |
@Configuration
|
|
|
29 |
@ComponentScan({"com.spice.profitmandi.*"})
|
|
|
30 |
public class WebConfig extends WebMvcConfigurerAdapter{
|
|
|
31 |
|
|
|
32 |
private static final String RESOURCES_PATTERN="/resources/**";
|
|
|
33 |
private static final String RESOURCES_LOCATION="/resources/";
|
|
|
34 |
|
| 21561 |
ashik.ali |
35 |
@Autowired
|
|
|
36 |
AuthenticationInterceptor authenticationInterceptor;
|
| 22107 |
ashik.ali |
37 |
|
|
|
38 |
@Autowired
|
|
|
39 |
RoleInterceptor roleInterceptor;
|
|
|
40 |
|
| 21555 |
kshitij.so |
41 |
@Override
|
|
|
42 |
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
|
|
43 |
registry.addResourceHandler(RESOURCES_PATTERN).addResourceLocations(RESOURCES_LOCATION);
|
|
|
44 |
}
|
|
|
45 |
|
| 21561 |
ashik.ali |
46 |
@Override
|
|
|
47 |
public void addInterceptors(InterceptorRegistry registry) {
|
| 22151 |
amit.gupta |
48 |
registry.addInterceptor(authenticationInterceptor).addPathPatterns("/**").excludePathPatterns("/login", "/login/", "/", "");
|
|
|
49 |
registry.addInterceptor(roleInterceptor).excludePathPatterns("/login", "/login/", "/register", "/register/", "", "/");
|
| 21561 |
ashik.ali |
50 |
}
|
|
|
51 |
|
| 23886 |
amit.gupta |
52 |
@Override
|
|
|
53 |
public void addFormatters(FormatterRegistry registry) {
|
|
|
54 |
DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();
|
|
|
55 |
registrar.setUseIsoFormat(true);
|
|
|
56 |
registrar.registerFormatters(registry);
|
|
|
57 |
}
|
|
|
58 |
|
| 23878 |
amit.gupta |
59 |
|
| 23886 |
amit.gupta |
60 |
|
| 23878 |
amit.gupta |
61 |
@Override
|
|
|
62 |
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
|
|
63 |
|
|
|
64 |
converters.add(new MappingJackson2HttpMessageConverter(objectMapper()));
|
| 23890 |
amit.gupta |
65 |
converters.add(new ResourceHttpMessageConverter());
|
| 23924 |
amit.gupta |
66 |
converters.add(new ByteArrayHttpMessageConverter());
|
| 23878 |
amit.gupta |
67 |
super.configureMessageConverters(converters);
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
private ObjectMapper objectMapper() {
|
|
|
71 |
ObjectMapper mapper = new ObjectMapper()
|
|
|
72 |
.registerModule(new ParameterNamesModule())
|
|
|
73 |
.registerModule(new Jdk8Module())
|
|
|
74 |
.registerModule(new JavaTimeModule()); // new module, NOT JSR310Module
|
|
|
75 |
return mapper;
|
|
|
76 |
}
|
|
|
77 |
|
| 21555 |
kshitij.so |
78 |
}
|