Guest User

Untitled

a guest
Aug 16th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.00 KB | None | 0 0
  1. @Configuration
  2. @EnableSwagger2
  3. @EnableWebMvc
  4. public class SwaggerConfig extends WebMvcConfigurerAdapter{
  5.  
  6. @Bean
  7. public Docket newsApi() {
  8. System.out.println("!@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@22");
  9. return new Docket(DocumentationType.SWAGGER_2)
  10. .groupName("Dialr")
  11. .apiInfo(apiInfo())
  12. .select()
  13. .paths(regex("/*.*"))
  14. .build();
  15. }
  16.  
  17. private ApiInfo apiInfo() {
  18. return new ApiInfoBuilder()
  19. .title("Spring REST Sample with Swagger")
  20. .description("Spring REST Sample with Swagger")
  21. .termsOfServiceUrl("http://www-03.ibm.com/software/sla/sladb.nsf/sla/bm?Open")
  22. .contact("Niklas Heidloff")
  23. .license("Apache License Version 2.0")
  24. .licenseUrl("https://github.com/IBM-Bluemix/news-aggregator/blob/master/LICENSE")
  25. .version("2.0")
  26. .build();
  27. }
  28.  
  29. }
  30.  
  31. <?xml version="1.0" encoding="UTF-8"?>
  32. <beans xmlns="http://www.springframework.org/schema/beans"
  33. xmlns:context="http://www.springframework.org/schema/context"
  34. xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  35. xmlns:p="http://www.springframework.org/schema/p"
  36. xsi:schemaLocation="
  37. http://www.springframework.org/schema/beans
  38. http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
  39. http://www.springframework.org/schema/context
  40. http://www.springframework.org/schema/context/spring-context-4.0.xsd
  41. http://www.springframework.org/schema/mvc
  42. http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
  43. <context:component-scan base-package="com.xx.yy.zz" />
  44.  
  45. <mvc:annotation-driven />
  46. <mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/"/>
  47. <mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/>
  48.  
  49. <context:annotation-config/>
  50. <bean name="swaggerConfig" class="com.xx.yy.SwaggerConfig"/>
  51.  
  52. </beans>
  53.  
  54. <?xml version="1.0" encoding="UTF-8"?>
  55. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  56. <display-name>Retail_SVC</display-name>
  57.  
  58.  
  59. <servlet>
  60. <servlet-name>rest</servlet-name>
  61. <servlet-class>
  62. org.springframework.web.servlet.DispatcherServlet
  63. </servlet-class>
  64. <init-param>
  65. <param-name>contextConfigLocation</param-name>
  66. <param-value>/WEB-INF/spring/rest-servlet.xml</param-value>
  67. </init-param>
  68. <load-on-startup>1</load-on-startup>
  69. </servlet>
  70.  
  71. <servlet-mapping>
  72. <servlet-name>rest</servlet-name>
  73. <url-pattern>/rest/*</url-pattern>
  74. </servlet-mapping>
  75. </web-app>
  76.  
  77. @Configuration
  78. @EnableSwagger2
  79. public class SwaggerConfig implements WebMvcConfigurer {
  80. @Bean
  81. public Docket productApi() {
  82. return new Docket(DocumentationType.SWAGGER_2)
  83. .select()
  84. .apis(RequestHandlerSelectors.basePackage("com.illary.controller"))
  85. .paths(PathSelectors.any())
  86. .build()
  87. .apiInfo(metaData());
  88. }
  89. private ApiInfo metaData() {
  90. return new ApiInfoBuilder()
  91. .title("Spring Boot Swagger App")
  92. .description(""Spring Boot Swagger Server App"")
  93. .version("1.0.0")
  94. .license("Apache License Version 2.0")
  95. .licenseUrl("https://www.apache.org/licenses/LICENSE-2.0"")
  96. .build();
  97. }
  98.  
  99. public ApiInfo apiInfo() {
  100. final ApiInfoBuilder builder = new ApiInfoBuilder();
  101. builder.title("Swagger Test App").version("1.0").license("(C) Copyright Test")
  102. .description("The API provides a platform to query build test swagger api");
  103.  
  104. return builder.build();
  105. }
  106.  
  107. @Override
  108. public void addResourceHandlers(ResourceHandlerRegistry registry) {
  109. registry.addResourceHandler("swagger-ui.html")
  110. .addResourceLocations("classpath:/META-INF/resources/");
  111.  
  112. registry.addResourceHandler("/webjars/**")
  113. .addResourceLocations("classpath:/META-INF/resources/webjars/");
  114. }
  115. }
Add Comment
Please, Sign In to add comment