我试图使用swagger2和springfox来实现api文档。 我的项目不是弹簧启动或maven,它依赖于xml文件。
我添加了课程:
SwaggerConfig
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableSwagger2
@PropertySource("classpath:swagger.properties")
@ComponentScan(basePackageClasses = ProductController.class)
@Configuration
public class SwaggerConfig {
private static final String SWAGGER_API_VERSION = "1.0";
private static final String LICENSE_TEXT = "License";
private static final String title = "Products REST API";
private static final String description = "RESTful API for Products";
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title(title)
.description(description)
.license(LICENSE_TEXT)
.version(SWAGGER_API_VERSION)
.build();
}
@Bean
public Docket productsApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.pathMapping("/")
.select()
.paths(PathSelectors.regex( "/*"))
.build();
}
}
所以当我运行tomcat服务器时,它运行正常而没有错误但是当我把以下链接:
没有任何反应。 我错过了一些配置或任何建议吗?
提前谢谢。
答案 0 :(得分:1)
问题得以解决
弹簧-config.xml中
<mvc:default-servlet-handler/>
<mvc:annotation-driven/>
<mvc:resources location="classpath:/META-INF/resources/" mapping="swagger-ui.html"></mvc:resources>
<mvc:resources location="classpath:/META-INF/resources/webjars/" mapping="/webjars/**"></mvc:resources>
<bean class="springfox.documentation.swagger2.configuration.Swagger2DocumentationConfiguration" id="swagger2Config"/>