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