Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Configuration
- @EnableSwagger2
- @EnableWebMvc
- public class SwaggerConfig extends WebMvcConfigurerAdapter{
- @Bean
- public Docket newsApi() {
- System.out.println("!@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@22");
- return new Docket(DocumentationType.SWAGGER_2)
- .groupName("Dialr")
- .apiInfo(apiInfo())
- .select()
- .paths(regex("/*.*"))
- .build();
- }
- private ApiInfo apiInfo() {
- return new ApiInfoBuilder()
- .title("Spring REST Sample with Swagger")
- .description("Spring REST Sample with Swagger")
- .termsOfServiceUrl("http://www-03.ibm.com/software/sla/sladb.nsf/sla/bm?Open")
- .contact("Niklas Heidloff")
- .license("Apache License Version 2.0")
- .licenseUrl("https://github.com/IBM-Bluemix/news-aggregator/blob/master/LICENSE")
- .version("2.0")
- .build();
- }
- }
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:p="http://www.springframework.org/schema/p"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context-4.0.xsd
- http://www.springframework.org/schema/mvc
- http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
- <context:component-scan base-package="com.xx.yy.zz" />
- <mvc:annotation-driven />
- <mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/"/>
- <mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/>
- <context:annotation-config/>
- <bean name="swaggerConfig" class="com.xx.yy.SwaggerConfig"/>
- </beans>
- <?xml version="1.0" encoding="UTF-8"?>
- <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">
- <display-name>Retail_SVC</display-name>
- <servlet>
- <servlet-name>rest</servlet-name>
- <servlet-class>
- org.springframework.web.servlet.DispatcherServlet
- </servlet-class>
- <init-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>/WEB-INF/spring/rest-servlet.xml</param-value>
- </init-param>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>rest</servlet-name>
- <url-pattern>/rest/*</url-pattern>
- </servlet-mapping>
- </web-app>
- @Configuration
- @EnableSwagger2
- public class SwaggerConfig implements WebMvcConfigurer {
- @Bean
- public Docket productApi() {
- return new Docket(DocumentationType.SWAGGER_2)
- .select()
- .apis(RequestHandlerSelectors.basePackage("com.illary.controller"))
- .paths(PathSelectors.any())
- .build()
- .apiInfo(metaData());
- }
- private ApiInfo metaData() {
- return new ApiInfoBuilder()
- .title("Spring Boot Swagger App")
- .description(""Spring Boot Swagger Server App"")
- .version("1.0.0")
- .license("Apache License Version 2.0")
- .licenseUrl("https://www.apache.org/licenses/LICENSE-2.0"")
- .build();
- }
- public ApiInfo apiInfo() {
- final ApiInfoBuilder builder = new ApiInfoBuilder();
- builder.title("Swagger Test App").version("1.0").license("(C) Copyright Test")
- .description("The API provides a platform to query build test swagger api");
- return builder.build();
- }
- @Override
- public void addResourceHandlers(ResourceHandlerRegistry registry) {
- registry.addResourceHandler("swagger-ui.html")
- .addResourceLocations("classpath:/META-INF/resources/");
- registry.addResourceHandler("/webjars/**")
- .addResourceLocations("classpath:/META-INF/resources/webjars/");
- }
- }
Add Comment
Please, Sign In to add comment