|
| 1 | +package info.xiaomo.javase; |
| 2 | + |
| 3 | +import io.swagger.annotations.ApiOperation; |
| 4 | +import org.springframework.boot.SpringApplication; |
| 5 | +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; |
| 6 | +import org.springframework.boot.autoconfigure.domain.EntityScan; |
| 7 | +import org.springframework.cache.annotation.EnableCaching; |
| 8 | +import org.springframework.context.annotation.Bean; |
| 9 | +import org.springframework.context.annotation.ComponentScan; |
| 10 | +import org.springframework.context.annotation.Configuration; |
| 11 | +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; |
| 12 | +import org.springframework.stereotype.Controller; |
| 13 | +import org.springframework.transaction.annotation.EnableTransactionManagement; |
| 14 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 15 | +import org.springframework.web.bind.annotation.RequestMethod; |
| 16 | +import org.springframework.web.servlet.ModelAndView; |
| 17 | +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; |
| 18 | +import springfox.documentation.annotations.ApiIgnore; |
| 19 | +import springfox.documentation.builders.ApiInfoBuilder; |
| 20 | +import springfox.documentation.builders.PathSelectors; |
| 21 | +import springfox.documentation.builders.RequestHandlerSelectors; |
| 22 | +import springfox.documentation.service.ApiInfo; |
| 23 | +import springfox.documentation.spi.DocumentationType; |
| 24 | +import springfox.documentation.spring.web.plugins.Docket; |
| 25 | +import springfox.documentation.swagger2.annotations.EnableSwagger2; |
| 26 | + |
| 27 | +/** |
| 28 | + * 把今天最好的表现当作明天最新的起点..~ |
| 29 | + * いま 最高の表現 として 明日最新の始発..~ |
| 30 | + * Today the best performance as tomorrow newest starter! |
| 31 | + * Created by IntelliJ IDEA. |
| 32 | + * |
| 33 | + * @author : xiaomo |
| 34 | + * github: https://github.com/xiaomoinfo |
| 35 | + * email: xiaomo@xiaomo.info |
| 36 | + * <p> |
| 37 | + * Date: 2016/4/1 15:38 |
| 38 | + * Description: 后台管理启动器 |
| 39 | + * Copyright(©) 2015 by xiaomo. |
| 40 | + **/ |
| 41 | +@Configuration |
| 42 | +@EnableAutoConfiguration |
| 43 | +@ComponentScan("info.xiaomo") |
| 44 | +@EntityScan("info.xiaomo.*.model") |
| 45 | +@EnableTransactionManagement |
| 46 | +@EnableJpaRepositories("info.xiaomo.*.dao") |
| 47 | +@EnableCaching |
| 48 | +@EnableSwagger2 |
| 49 | +@Controller |
| 50 | +public class XiaomoMain extends WebMvcConfigurerAdapter { |
| 51 | + |
| 52 | + public static void main(String[] args) throws Exception { |
| 53 | + SpringApplication.run(XiaomoMain.class, args); |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * 接口 |
| 58 | + * |
| 59 | + * @return 接口 |
| 60 | + */ |
| 61 | + @RequestMapping(value = "/", method = RequestMethod.GET) |
| 62 | + @ApiIgnore() |
| 63 | + @ApiOperation(value = "重定向到api首页") |
| 64 | + public ModelAndView api() { |
| 65 | + return new ModelAndView("redirect:/swagger-ui.html"); |
| 66 | + } |
| 67 | + |
| 68 | + |
| 69 | + @Bean |
| 70 | + public Docket createRestApi() { |
| 71 | + return new Docket(DocumentationType.SWAGGER_2) |
| 72 | + .apiInfo(apiInfo()) |
| 73 | + .select() |
| 74 | + .apis(RequestHandlerSelectors.basePackage("info.xiaomo.website")) |
| 75 | + .paths(PathSelectors.any()) |
| 76 | + .build(); |
| 77 | + } |
| 78 | + |
| 79 | + private ApiInfo apiInfo() { |
| 80 | + return new ApiInfoBuilder() |
| 81 | + .title("Spring Boot中使用Swagger2构建RESTful APIs") |
| 82 | + .description("api根地址:http://api.xiaomo.info:8080/") |
| 83 | + .termsOfServiceUrl("https://xiaomo.info/") |
| 84 | + .contact("小莫") |
| 85 | + .version("1.0") |
| 86 | + .build(); |
| 87 | + } |
| 88 | + |
| 89 | +} |
0 commit comments