| 21165 |
ashik.ali |
1 |
package com.spice.profitmandi.web.config;
|
|
|
2 |
|
| 21220 |
ashik.ali |
3 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 21272 |
kshitij.so |
4 |
import org.springframework.context.annotation.Bean;
|
| 21165 |
ashik.ali |
5 |
import org.springframework.context.annotation.ComponentScan;
|
|
|
6 |
import org.springframework.context.annotation.Configuration;
|
|
|
7 |
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
|
|
8 |
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
|
|
9 |
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
|
|
10 |
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
|
|
11 |
|
| 21236 |
ashik.ali |
12 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
|
|
13 |
import com.spice.profitmandi.web.interceptor.ApiRequestInterceptor;
|
|
|
14 |
import com.spice.profitmandi.web.interceptor.RoleRequestInterceptor;
|
| 21220 |
ashik.ali |
15 |
|
| 21272 |
kshitij.so |
16 |
import springfox.documentation.builders.PathSelectors;
|
|
|
17 |
import springfox.documentation.builders.RequestHandlerSelectors;
|
|
|
18 |
import springfox.documentation.service.ApiInfo;
|
|
|
19 |
import springfox.documentation.spi.DocumentationType;
|
|
|
20 |
import springfox.documentation.spring.web.plugins.Docket;
|
|
|
21 |
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
|
|
22 |
|
| 21165 |
ashik.ali |
23 |
@Configuration
|
|
|
24 |
@EnableWebMvc
|
| 21272 |
kshitij.so |
25 |
@EnableSwagger2
|
| 21220 |
ashik.ali |
26 |
@ComponentScan("com.spice.profitmandi.*")
|
| 21165 |
ashik.ali |
27 |
public class WebMVCConfig extends WebMvcConfigurerAdapter{
|
|
|
28 |
|
|
|
29 |
private static final String RESOURCES_PATTERN="/resources/**";
|
|
|
30 |
private static final String RESOURCES_LOCATION="/resources/";
|
|
|
31 |
|
| 21220 |
ashik.ali |
32 |
@Autowired
|
| 21236 |
ashik.ali |
33 |
ApiRequestInterceptor apiRequestInterceptor;
|
| 21165 |
ashik.ali |
34 |
|
| 21236 |
ashik.ali |
35 |
@Autowired
|
|
|
36 |
RoleRequestInterceptor roleRequestInterceptor;
|
|
|
37 |
|
| 21272 |
kshitij.so |
38 |
|
|
|
39 |
@Bean
|
|
|
40 |
public Docket api() {
|
|
|
41 |
return new Docket(DocumentationType.SWAGGER_2).select()
|
|
|
42 |
.apis(RequestHandlerSelectors.any())
|
|
|
43 |
.paths(PathSelectors.any()).build()
|
|
|
44 |
.apiInfo(apiInfo());
|
|
|
45 |
}
|
|
|
46 |
|
| 21165 |
ashik.ali |
47 |
@Override
|
| 21272 |
kshitij.so |
48 |
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
|
|
49 |
registry.addResourceHandler("swagger-ui.html")
|
|
|
50 |
.addResourceLocations("classpath:/META-INF/resources/");
|
|
|
51 |
registry.addResourceHandler("/webjars/**")
|
|
|
52 |
.addResourceLocations("classpath:/META-INF/resources/webjars/");
|
|
|
53 |
registry.addResourceHandler(RESOURCES_PATTERN).addResourceLocations(RESOURCES_LOCATION);
|
|
|
54 |
}
|
| 21165 |
ashik.ali |
55 |
|
|
|
56 |
@Override
|
|
|
57 |
public void addInterceptors(InterceptorRegistry registry) {
|
| 21236 |
ashik.ali |
58 |
registry.addInterceptor(apiRequestInterceptor).addPathPatterns(ProfitMandiConstants.URL_API, ProfitMandiConstants.URL_API + "/");
|
|
|
59 |
registry.addInterceptor(roleRequestInterceptor).addPathPatterns(ProfitMandiConstants.URL_ROLE, ProfitMandiConstants.URL_ROLE + "/");
|
| 21165 |
ashik.ali |
60 |
}
|
| 21272 |
kshitij.so |
61 |
|
|
|
62 |
private ApiInfo apiInfo() {
|
|
|
63 |
@SuppressWarnings("deprecation")
|
|
|
64 |
ApiInfo apiInfo = new ApiInfo(
|
|
|
65 |
"ProfitMandi API",
|
|
|
66 |
"Api's for profitmandi app",
|
|
|
67 |
"API TOS",
|
|
|
68 |
"Terms of service",
|
|
|
69 |
"New Spice Solutions Pvt. Ltd.",
|
|
|
70 |
"License of API",
|
|
|
71 |
"API license URL");
|
|
|
72 |
return apiInfo;
|
|
|
73 |
}
|
| 21220 |
ashik.ali |
74 |
}
|