gpt4 book ai didi

java - Tomcat:获取基于 Jersey 的 Rest 服务的短 URL

转载 作者:行者123 更新时间:2023-11-28 23:01:31 25 4
gpt4 key购买 nike

我有一个基于 Jersey 的 Rest 服务在 tomcat 服务器上运行。没有用户界面,只有一个提供一些休息服务的服务器。现在,要访问此服务,我必须输入的 URL 很长。类似于 localhost:8080/MyApp/url_pattern/classPath/method 其中 MyApp 是我部署的 webapp,url_pattern 是我在 web.xml 的 servlet 映射中定义的模式,classPath 和方法是分别为类和方法添加 @Path 注解。是否可以缩短它以便我摆脱此 URL 的 MyApp 和 url_pattern 部分。类似于 localhost:8080/classPath/method

PS: 这个服务器上只有一个 webApp 运行,所以没有 MyApp 部分

最佳答案

我不认为你可以从 url 中删除你想要的所有内容,但你绝对可以通过将 MyApp 部分设为 tomcat 的根应用程序来删除它。

这个相关链接上的回答描述得很好,如何将您的应用程序设置为根应用程序。因此,您无需在 url 中包含应用程序名称即可访问您的 REST 服务:

Setting default application in tomcat 7

从以上链接复制的内容:

First Method:

first shutdown your tomcat [from the bin directory (sh shutdown.sh)] then you must delete all the content of your tomcat webapps folder (rm -fr *) then rename your WAR file to ROOT.war finally start your tomcat [from the bin directory (sh startup.sh)]

Second Method:

leave your war file in CATALINA_BASE/webapps, under its original name - turn off autoDeploy and deployOnStartup in your Host element in the server.xml file. explicitly define all application Contexts in server.xml, specifying both path and docBase. You must do this, because you have disabled all the Tomcat auto-deploy mechanisms, and Tomcat will not deploy your applications anymore unless it finds their Context in the server.xml.

Note:

that this last method also implies that in order to make any change to any application, you will have to stop and restart Tomcat.

Third Method:

Place your war file outside of CATALINA_BASE/webapps (it must be outside to prevent double deployment). - Place a context file named ROOT.xml in CATALINA_BASE/conf//. The single element in this context file MUST have a docBase attribute pointing to the location of your war file. The path element should not be set - it is derived from the name of the .xml file, in this case ROOT.xml. See the Context Container above for details.

关于java - Tomcat:获取基于 Jersey 的 Rest 服务的短 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18372065/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com