-
-
Save jpukg/ddd1fab0b45508ced0b50e3b0be87bd0 to your computer and use it in GitHub Desktop.
sample Spring mvc Config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Configuration | |
| @EnableWebMvc | |
| @EnableSwagger2 | |
| @ComponentScan(basePackageClasses = RootPackageMarker.class, useDefaultFilters = false, includeFilters = { | |
| @ComponentScan.Filter(type = FilterType.ANNOTATION, value = Controller.class), @ComponentScan.Filter(type = FilterType.ANNOTATION, value = ControllerAdvice.class)}) | |
| @Import({SwaggerConfig.class, SpringSecurityConfig.class}) | |
| public class SpringMvcConfig extends WebMvcConfigurerAdapter { | |
| @Bean | |
| public InternalResourceViewResolver internalResourceViewResolver() { | |
| return new InternalResourceViewResolver() { | |
| { | |
| setOrder(9); | |
| setPrefix("/WEB-INF/jsp/"); | |
| setSuffix(".jsp"); | |
| } | |
| }; | |
| } | |
| @Bean(name = "multipartResolver") | |
| public StandardServletMultipartResolver multipartResolver() { | |
| return new StandardServletMultipartResolver(); | |
| } | |
| @Override | |
| public void addResourceHandlers(final ResourceHandlerRegistry registry) { | |
| registry.addResourceHandler("/static/**").addResourceLocations("/static/"); | |
| // swagger 설정 | |
| registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/"); | |
| registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); | |
| } | |
| @Override | |
| public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { | |
| converters.add(new MappingJackson2HttpMessageConverter(ObjectMapperFactory.json())); | |
| converters.add(new Jaxb2RootElementHttpMessageConverter()); | |
| converters.add(new StringHttpMessageConverter()); | |
| } | |
| @Override | |
| public void configureContentNegotiation(ContentNegotiationConfigurer configurer) { | |
| // configurer.favorPathExtension(false).favorParameter(true).parameterName("mediaType").ignoreAcceptHeader(true).useJaf(false).defaultContentType( | |
| // MediaType.APPLICATION_JSON).mediaType("xml", MediaType.APPLICATION_XML).mediaType("json", MediaType.APPLICATION_JSON); | |
| configurer.favorParameter(true).useJaf(false).defaultContentType(MediaType.APPLICATION_JSON); | |
| } | |
| @Override | |
| public void configurePathMatch(PathMatchConfigurer configurer) { | |
| configurer.setUseSuffixPatternMatch(false); | |
| } | |
| @Bean | |
| public AuthorizationInterceptor authorizationInterceptor() { | |
| return new AuthorizationInterceptor(); | |
| } | |
| @Override | |
| public void addInterceptors(InterceptorRegistry registry) { | |
| registry.addInterceptor(authorizationInterceptor()).excludePathPatterns("/static/**", "swagger-ui.html", "/webjars/**", "/v2/api-docs", "/configuration/security", | |
| "/configuration/ui", "/swagger-resources", "/_test/**"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment