Last active
August 5, 2019 02:09
-
-
Save sojw/d8c55001b28d838a096c3256d4b1a7ac to your computer and use it in GitHub Desktop.
Spring SwaggerConfiguration JavaConfig example
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
| @Api(value = "Some API") | |
| @RestController | |
| @RequestMapping(value = "/Service") | |
| public class SampleApiContorller { | |
| @Autowired | |
| private ResponseEntityUtil responseEntityUtil; | |
| @Autowired | |
| private ServiceApiProxyFactory serviceApiProxyFactory; | |
| @ApiOperation(value = "Category List API", notes = "get some list ", response = Category.class, responseContainer = "List") | |
| @RequestMapping(value = {"/CategoryList.json"}, produces = Type.JSON_UTF8, method = RequestMethod.GET) | |
| public ResponseEntity<?> legacyCategoryList( | |
| @ApiParam(value = "service id", required = true) @RequestParam("serviceId") String serviceId, | |
| @ApiParam(hidden = true) @ModelAttribute("loginInfo") LoginInfo loginInfo) throws Exception { | |
| List<Category> categories = serviceApiProxyFactory.getCategoryList(loginInfo.getId()); | |
| return responseEntityUtil.success(categories); | |
| } | |
| } |
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(basePackages = "com.naver", useDefaultFilters = false, includeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION, value = Controller.class), | |
| @ComponentScan.Filter(type = FilterType.ANNOTATION, value = ControllerAdvice.class)}) | |
| @Import({CoreApplicationContextConfiguration.class, SwaggerConfig.class}) | |
| public class SpringMvcConfiguration extends WebMvcConfigurerAdapter { | |
| @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/"); | |
| } | |
| } |
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 | |
| @EnableSwagger2 | |
| public class SwaggerConfiguration { | |
| @Bean | |
| public Docket documentation() { | |
| return new Docket(DocumentationType.SWAGGER_2).select().apis( | |
| RequestHandlerSelectors.basePackage("api.class.packagename")).paths(PathSelectors.any()).build().pathMapping( | |
| "/").apiInfo(apiInfo()); | |
| } | |
| @Bean | |
| UiConfiguration uiConfig() { | |
| return new UiConfiguration("validatorUrl"); | |
| } | |
| private ApiInfo apiInfo() { | |
| return new ApiInfo("Swagger API", "Swagger API Desc", "1.0", "My Apps API terms of service", | |
| "[email protected]", "", ""); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment