SSM整合Swagge出现Can't read swagger JSON from http://localhost:8080/v2/api-doc

光年之外_yi 2020-09-29 04:31:33
想请教各位大佬怎么解决这个问题

这是applicationContext.xml配置文件的代码

<bean class="com.gx.util.SwaggerConfig"/>
<context:component-scan base-package="springfox"/>
<mvc:resources mapping="/swagger/**" location="/swagger/" cache-period="31556926" />

这是swagger工具类

public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo()).select()
//扫描指定包中的swagger注解
.apis(RequestHandlerSelectors.basePackage("com.gx.web"))
//.apis(RequestHandlerSelectors.basePackage("com.gx.web"))
//扫描所有有注解的api,用这种方式更灵活
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
.paths(PathSelectors.any())
.build();
}

/**
* 这是匹配api的信息
*
* @return
*/
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("API文档")
.description("API测试文档")
.termsOfServiceUrl("")
.license("")
.version("1.0.0")
.build();
}
}

这是index.html中的url地址

var url = window.location.search.match(/url=([^&]+)/);
if (url && url.length > 1) {
url = decodeURIComponent(url[1]);
} else {
url = "/v2/api-docs";
}

这是controller的代码

@Controller
@RequestMapping("/user")
@Api(value = "用户接口", description = "用户相关api")
public class UserController {

private Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create();
private Object result;

@Autowired
private IUserService userService;

@RequestMapping("/loginsPage")
@ApiOperation(value = "登录", notes = "后台登录", response = ModelAndView.class)
public ModelAndView loginsPage() {
ModelAndView mv = new ModelAndView("/login");
return mv;
}
}

...全文
9932 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
KeepSayingNo 2020-09-30
  • 打赏
  • 举报
回复
KeepSayingNo 2020-09-30
  • 打赏
  • 举报
回复
看代码没什么问题
光年之外_yi 2020-09-30
  • 打赏
  • 举报
回复
看了,但是我并不知道该怎么做

58,442

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧