首先是访问http://ip:/doc.htmlhttp://${host}:${port}/doc.htmlhttp://ip:/doc.html报错
1、假如是SpringSecurity项目,可能是configure(WebSecurity web)没有放行,代码如下
@Configuration
@Lazy
public class SecurityConfig extends WebSecurityConfigurerAdapter{
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers(
"/login",
"/logout",
"/css/**",
"/js/**",
"/index.html",
"favicon.ico",
"/doc.html",
"/webjars/**",
"/swagger-resources/**",
"/v2/api-docs/**"
);
}
}
在启动类中修改成如下代码
@SpringBootApplication
@MapperScan("mapper包名")
@EnableWebMvc
public class YebApplication implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/doc.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").
addResourceLocations("classpath:/META-INF/resources/webjars/");
}
public static void main(String[] args) {
SpringApplication.run(YebApplication.class, args);
}
}
Swagger配置类
@Configuration
@EnableSwagger2
public class Swagger2Config {
@Bean
public Docket createRestApi(){
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
// 初始化并返回一个API选择构造器
.select()
// apis:添加路径选择条件,根据包名扫描controller类
//.apis(RequestHandlerSelectors.basePackage("要扫描包名")) // 如果不行使用下面的
// 根据注解扫描,只扫描标有@RestController的类
.apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
// 设置路径筛选,满足条件的路径,该断言总为true
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo(){
return new ApiInfoBuilder()
.title("标题")
.description("描述档")
.contact(new Contact("作者名", "url", "邮箱"))
.version("1.0") //版本
.build();
}
}
Controller类文章来源:https://www.toymoban.com/news/detail-540711.html
@Api(value = "/hello", tags = "测试hello")
@RestController
public class HelloController {
@ApiOperation("hello")
@GetMapping("/hello")
public String hello(){
return "hello";
}
}
Swagger依赖文章来源地址https://www.toymoban.com/news/detail-540711.html
<!-- swagger2 依赖-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<!-- swagger2 第三方ui依赖-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.6</version>
</dependency>
到了这里,关于swagger-bootstrap-ui 报错No mapping for GET /doc.htm,404l,以及无法显示接口文档的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!