changing app root for spring mvc app on tomcat
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.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http: //www.springframework.org/schema/context http: //www.springframework.org/schema/context/spring-context-3.0.xsd
http: //www.springframework.org/schema/beans http: //www.springframework.org/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>
my RESTEasy resource class
@Controller
@Path("/contacts")
public class ContactsResource {
...
You can set these in your Tomcat server.xml.
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" />
This should allow you to access it as http: //localhost:8080/contacts
Set the path to "myservice" like below
<Context docBase="examples-resteasy-2.1-SNAPSHOT" path="/myservice" reloadable="true" />
should allow you to access it as http: //localhost:8080/myservice/contacts
精彩评论