api-docs 早些时候工作正常。它停止工作,现在我得到了
Can't read swagger JSON from http://localhost:9000/api-docs/
如果我更改 src/main/webapp/swagger-ui/index.html
var apiUrl = "http://localhost:8080/swagger-ui/index.html";
我得到“无法从服务器读取。它可能没有适当的访问控制源设置。”
api-docs 早些时候工作正常。它停止工作,现在我得到了
Can't read swagger JSON from http://localhost:9000/api-docs/
如果我更改 src/main/webapp/swagger-ui/index.html
var apiUrl = "http://localhost:8080/swagger-ui/index.html";
我得到“无法从服务器读取。它可能没有适当的访问控制源设置。”
通过更改 gruntfile.js 以在连接/代理部分中包含以下行,请参阅 Jerome 在https://github.com/jhipster/generator-jhipster/issues/277上的修复
,{
context: '/api-docs',
host: 'localhost',
port: 8080,
https: false,
changeOrigin: false
}
我遇到了同样的问题,发现生成的类有包com.mycompany.myapp.config.apidoc
,但它们实际上在com.mycompany.myapp.apidoc
.
您可以通过将 java 文件移动到正确的包来解决此问题com.mycompany.myapp.config.apidoc
。
为此,您必须启用 CORS,只需将这 3 个 res.header 行添加到您的 API 中,然后在您访问该 API 时将启用 CORS,这样您就不会收到访问控制原点设置之类的错误。
app.get('/swaggerJson', function(req, res){
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With");
res.header("Access-Control-Allow-Methods", "GET, PUT, POST, OPTIONS");
res.json(swaggerJSON);
});
希望对你有帮助..