【发布时间】:2023-08-18 05:50:01
【问题描述】:
有一个 web 应用程序在 tomcat 中的 war 文件中运行,作为其中的一部分,我有 jax-rs rest apis 用 jax-rs 实现并由 jersey 绑定。这些其余的 api 有一些招摇的注释,但是我似乎无法让招摇的 ui 正常运行。
结构
warFile
+docs
----swagger is here
+web-inf
++web.xml
++lib
----all my jax-rs jars here
+meta-inf
----nothing
我定义的球衣配置
public class JerseyConfig extends ResourceConfig {
public JerseyConfig() throws Exception {
packages("com.myapp.somefiles");
BeanConfig config = new BeanConfig();
config.setBasePath("rest");
config.setResourcePackage("com.myapp.somefiles");
config.setScan(true);
}
Web.xml
<servlet>
<servlet-name>com.myapp.somefile.JerseyConfig</servlet-name>
</servlet>
<servlet-mapping>
<servlet-name>com.myapp.somefile.JerseyConfig</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
所以当我在 war 文件中有 swagger-ui html 文件时,我可以访问它们; 本地主机:8181/warFile/docs。但是,我希望将此加载到与我的 rest api 相同的 URL 上,可能是 localhost:8181/warFile/rest/docs
我可以在 localhost:8181/warFile/rest/swagger.json 访问 swagger.json 文件
我是否需要在我的 servlet 或 beanconfig 的上下文中使用类加载器加载 swagger? swagger-ui 也可以与 /lib 目录中的 jar 依赖项之一打包。我可以以某种方式引用它吗?
【问题讨论】:
-
您是否有 index.html 在其中提供招摇网址? localhost:8181/warFile/docs 之类的东西?
-
是的,当我加载 localhost:8181/warFile/docs 时,swagger-ui 将正确呈现。我想要做的是将它附加到与 'localhost:8181/warFile/rest' 处的 jax-rs 相同的 servlet 或 uri 路径。这是可能的,甚至是正确的方法吗?
-
这台服务器是专门用于 Swagger 的吗?如果是这种情况,那么您将朝着正确的方向前进。您在 index.html 中提供了什么网址?
-
服务器不是专门用于swagger的,我是用一些jax-rs web服务打包一个war文件。就是想知道打包swagger-ui最好的方法是什么,应该只是war文件中的一个目录吗?
-
让我重新表述我的问题。你会在这台服务器上只有其余的 api 吗?因为如果它不是并且你仍然想保持相同的 URL 来访问你的其他 jsp/html 文件和招摇,那么就没有办法区分它们。
标签: java jersey jax-rs jersey-2.0 swagger-ui