简体   繁体   中英

Spring MVC base/root URL is the same with war name

I created a basic rest service using Spring MVC with xml config. My app name is: myservice . When i create a war from it, I receive a war named myervice-1.0.0 . In conclusion, I have to access my application through http://localhost:8080/myservice-1.0.0/resource . I'd like to be just 'myservice', like project name. What can I do? Thanks a lot. I'm using tomcat + gradle. web.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. 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.

If you double click on the server definition in STS, you will see a "modules" tab. 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. If I recall correctly, by default Tomcat uses the file name name of the zipped or exploded .war. In either case, you can over-ride it.

see more about it here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM