我正在使用Spring MVC 3.0上的示例RESTEasy 2.0資源,並且依賴於Tomcat 6.我可以通過http:// localhost:8080/examples-resteasy- 2.1-SNAPSHOT /聯繫人,但我想通過訪問http:// localhost:8080/contacts甚至http:// localhost:8080/myservice/contacts在tomcat上更改spring mvc應用程序的應用程序根目錄
有什麼我需要改變我的應用程序映射到路徑?
的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 {
...
謝謝。我會嘗試server.xml的方式。我唯一擔心的是,Tomcat文檔和其他人強烈阻止通過server.xml並鼓勵META-INF/context.xml – pastafarian 2010-09-23 13:38:19
@pastafarian:多數民衆贊成真實,但在6.0我沒有得到它通過META-INF工作,只有服務器.XML – JoseK 2010-09-24 04:31:22