2010-09-22 80 views
1

我正在使用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 { 
... 

回答

6

你可以在Tomcat server.xml中設置這些。

在下面的<Host>內添加一個<Context>元素,它將您的examples-resteasy-2.1-SNAPSHOT設置爲默認的Web應用程序。

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

這應該允許您訪問它爲http://本地主機:8080 /觸點

設置,如路徑 「爲MyService」 的

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

應該允許您訪問作爲http:// localhost:8080/myservice/contacts

+0

謝謝。我會嘗試server.xml的方式。我唯一擔心的是,Tomcat文檔和其他人強烈阻止通過server.xml並鼓勵META-INF/context.xml – pastafarian 2010-09-23 13:38:19

+0

@pastafarian:多數民衆贊成真實,但在6.0我沒有得到它通過META-INF工作,只有服務器.XML – JoseK 2010-09-24 04:31:22

相關問題