swagger请求使用主机和端口,因此浏览器控制台XMLHttpRequest cannot load http://115.159.22.159:9001/bp/api/v1/user/1. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://twogoods.cc' is therefore not allowed access.
怎么解决呢?
答案 0 :(得分:2)
@Bean
public Docket categoryApi() {
return new Docket(DocumentationType.SWAGGER_2)
.host("twogoods.cc")
.groupName("bookplatform-api")
.apiInfo(apiInfo())
.select()
.paths(apiPaths())
.build()
.directModelSubstitute(java.sql.Timestamp.class, java.sql.Date.class)
.enableUrlTemplating(false);
}
host()
方法!!!
答案 1 :(得分:0)
您可以使用host(..)
和protocols(..)
方法覆盖默认值。
@Bean
public Docket customImplementation() {
return new Docket(DocumentationType.SWAGGER_2)
.protocols(Collections.singleton("https"))
.host("twogoods.cc")
.select()
.build();
}