英文:
Changing restAPI URI
问题
我已经在Java中创建了一个名为hello
的应用程序,我的class
如下所示:
@Path("/test")
class TestAPI
{
@GET
@Path("/hi")
public String sayHi()
{
return "Hi I am Shweta";
}
}
我正在使用以下方式访问该应用程序:
GET http://localhost:8080/hello/test/hi
是否有任何方法可以从URI
中删除hello
,或者在不更改应用程序的情况下替换它?
如果我想要像这样访问:http://localhost:8080/test/hi
,我需要进行什么更改?我正在使用maven
。
英文:
I have created an application in java with the name hello
. my class
is below
@Path("/test")
class TestAPI
{
@GET
@Path("/hi")
public String sayHi()
{
return "Hi I am Shweta";
}
}
I am accessing this application using
GET http://localhost:8080/hello/test/hi
Is there anyway I can remove hello
from URI
or I can replace the same without changing application.
If I need to access like http://localhost:8080/test/hi
what changes I need to do? I am using maven
.
答案1
得分: 0
可以在您的服务器上进行此操作。假设您正在使用Tomcat部署应用程序,然后请查阅其配置文件,并将上下文路径更改为'/'。这样就可以正常工作了。您只需检查在您使用的任何服务器中上下文路径的定义位置,然后将路径替换为'/'即可。
英文:
Yes you can do it in your server.Say if you are using tomcat to deploy your application,Then go through its configuration file and change the context path to '/'.It will work.You just need to check where context path is defined in what ever server you are using and just replace the path with '/'.
专注分享java语言的经验与见解,让所有开发者获益!
评论