[英]Spring MVC base/root URL is the same with war name
I created a basic rest service using Spring MVC with xml config.我使用带有 xml 配置的 Spring MVC 创建了一个基本的休息服务。 My app name is: myservice .
我的应用程序名称是: myservice 。 When i create a war from it, I receive a war named myervice-1.0.0 .
当我从中创建战争时,我会收到一个名为myervice-1.0.0的战争。 In conclusion, I have to access my application through http://localhost:8080/myservice-1.0.0/resource .
总之,我必须通过http://localhost:8080/myservice-1.0.0/resource访问我的应用程序。 I'd like to be just 'myservice', like project name.
我只想成为“myservice”,比如项目名称。 What can I do?
我能做什么? Thanks a lot.
非常感谢。 I'm using tomcat + gradle.
我正在使用 tomcat + gradle。 web.xml:
网页.xml:
<servlet>
<servlet-name>webappservice</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>webappservice</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
You can rename the war name.您可以重命名战争名称。 If you are using maven as build tool.
如果您使用 maven 作为构建工具。 Then you can use below solution.
然后您可以使用以下解决方案。
<build>
<finalName>myservice</finalName>
. . .
</build>
It will better if you can share some configuration details like pom.xml,web.xml etc.如果你能分享一些配置细节,比如 pom.xml、web.xml 等,那就更好了。
If you double click on the server definition in STS, you will see a "modules" tab.如果您双击 STS 中的服务器定义,您将看到一个“模块”选项卡。 From there, you can edit the "Path" and set it to whatever you want.
从那里,您可以编辑“路径”并将其设置为您想要的任何内容。 When you select "Run on Server", STS has to define a context path and simply defaults it to last element of the default package.
当您选择“在服务器上运行”时,STS 必须定义一个上下文路径并将其默认为默认包的最后一个元素。 If I recall correctly, by default Tomcat uses the file name name of the zipped or exploded .war.
如果我没记错的话,默认情况下 Tomcat 使用压缩或分解的 .war 的文件名。 In either case, you can over-ride it.
在任何一种情况下,您都可以超越它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.