在tomcat上更改Spring MVC应用程序的应用程序根

编程入门 行业动态 更新时间:2024-10-11 15:20:10
本文介绍了在tomcat上更改Spring MVC应用程序的应用程序根的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在Spring MVC 3.0上使用示例RESTEasy 2.0资源并依赖于Tomcat6.我可以通过localhost:8080/examples-resteasy-2.1-SNAPSHOT/contacts来获取资源,但是我想通过localhost:8080/contacts甚至localhost:8080/myservice/contacts来访问

I am working with a sample RESTEasy 2.0 resource on Spring MVC 3.0 and deplying to Tomcat 6. I can get to my resource through http: //localhost:8080/examples-resteasy-2.1-SNAPSHOT/contacts but I would like to access through http: //localhost:8080/contacts or even http: //localhost:8080/myservice/contacts

我的应用程序映射到路径的方式是否需要更改?

Is there something I need to change in the way my application is mapped to the path?

Web.xml

<web-app> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:springmvc-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>/contacts/*</url-pattern> </servlet-mapping> </web-app>

springmvc-servlet.xml

<beans xmlns="http: //www.springframework/schema/beans" xmlns:xsi="www.w3/2001/XMLSchema-instance" xmlns:context="www.springframework/schema/context" xsi:schemaLocation=" http: //www.springframework/schema/context http: //www.springframework/schema/context/spring-context-3.0.xsd http: //www.springframework/schema/beans http: //www.springframework/schema/beans/spring-beans.xsd "> <context:component-scan base-package="org.jboss.resteasy.examples.springmvc" /> <context:annotation-config /> <import resource="classpath:springmvc-resteasy.xml" /> <!-- this is included in the resteasy-spring library--> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="prefix" value="/WEB-INF/" /> <property name="suffix" value=".jsp" /> </bean> </beans>

我的RESTEasy资源类别

@Controller @Path("/contacts") public class ContactsResource { ...

推荐答案

您可以在Tomcat server.xml中进行设置.

You can set these in your Tomcat server.xml.

在<Host>内添加一个<Context>元素,如下所示,该元素将您的examples-resteasy-2.1-SNAPSHOT设置为默认Web应用.

Add a <Context> element within the <Host> like below which sets your examples-resteasy-2.1-SNAPSHOT as the default web app.

<Context docBase="examples-resteasy-2.1-SNAPSHOT" path="" reloadable="true" />

这应该允许您以localhost:8080/contacts

This should allow you to access it as http: //localhost:8080/contacts

将路径设置为"myservice",如下所示

Set the path to "myservice" like below

<Context docBase="examples-resteasy-2.1-SNAPSHOT" path="/myservice" reloadable="true" />

应该允许您以localhost:8080/myservice/contacts

should allow you to access it as http: //localhost:8080/myservice/contacts

更多推荐

在tomcat上更改Spring MVC应用程序的应用程序根

本文发布于:2023-11-28 11:36:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1642239.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   tomcat   Spring   MVC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!