我正在使用Spring MVC 3.0上的示例RESTEasy 2.0资源并依赖于Tomcat6。我可以通过http://localhost:8080/examples- resteasy-2.1-SNAPSHOT/contacts来获取资源,但是我想通过http:// localhost:8080 / contacts甚至http:// localhost:8080 / myservice / contacts
我的应用程序映射到路径的方式是否需要更改?
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>
我的RESTEasy资源类别
@Controller @Path("/contacts") public class ContactsResource { ...
您可以在Tomcat server.xml中进行设置。
<Context>在<Host>下面的类似图中添加一个元素,将您设置examples- resteasy-2.1-SNAPSHOT为默认Web应用程序。
<Context>
<Host>
examples- resteasy-2.1-SNAPSHOT
<Context docBase="examples-resteasy-2.1-SNAPSHOT" path="" reloadable="true" />
这应该允许您以http:// localhost:8080 / contacts访问它
将路径设置为“ myservice”,如下所示
<Context docBase="examples-resteasy-2.1-SNAPSHOT" path="/myservice" reloadable="true" />
应该允许您以http:// localhost:8080 / myservice / contacts访问它