之前配置过springboot,相比ssm要简单很多,现在记录一下ssm的配置
在pom.xml中加入依赖
io.springfox
springfox-swagger2
2.6.1
io.springfox
springfox-swagger-ui
2.6.1
添加配置类SwaggerConfig.java
@WebAppConfiguration
@EnableSwagger2
@EnableWebMvc
@ComponentScan(basePackages = "com.maxcore.controller")
public class SwaggerConfig {
@Bean
public Docket customDocket() {
//
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.build()
.apiInfo(apiInfo());
}
private ApiInfo apiInfo() {
Contact contact = new Contact("娜", "https://www.baidu.me", "[email protected]");
return new ApiInfo("仿前台API接口",//大标题 title
"Swagger测试demo",//小标题
"0.0.1",//版本
"www.baidu.com",//termsOfServiceUrl
contact,//作者
"Blog",//链接显示文字
"https://www.baidu.me"//网站链接
);
}
}
在dispatcher-servlet.xml(springmvc的配置文件)中加入如下配置
要在controller层添加注解
image
最后启动项目,访问swagger接口文档的路径一定要对,不然一直报404,你以为你没配置对,其实是你路径不对,笔者在这里表示有很痛的领悟
笔者的本地的访问路径是 http://localhost/jianShuSSM_war/swagger-ui.html
一般都是
http://ip地址:端口(默认80,不显示)/项目名/swagger-ui.html
image
image
image
image
image
image
image
终
github
个人网站