2010-09-22 8 views
1

Je travaille avec un exemple de ressource RESTEasy 2.0 sur Spring MVC 3.0 et déployer vers Tomcat 6. Je peux accéder à ma ressource via http: // localhost: 8080/examples-resteasy- 2.1-SNAPSHOT/contacts mais je voudrais accéder à travers http: // localhost: 8080/contacts ou même http: // localhost: 8080/myservice/contactschanger l'application racine pour printemps mvc app sur tomcat

Y at-il quelque chose que je dois changer dans la façon dont mon application est mappé sur le chemin?

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> 

ma ressource RESTEasy classe

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

Répondre

6

Vous pouvez les définir dans votre serveur Tomcat.xml.

Ajouter un <Context> élément dans le <Host> comme ci-dessous qui définit votre examples-resteasy-2.1-SNAPSHOT comme application Web par défaut.

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

Cela devrait vous permettre d'y accéder http: // localhost: 8080/contacts

Définissez le chemin vers "myservice" comme ci-dessous

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

devrait vous permettre d'y accéder comme http: // localhost: 8080/myservice/contacts

+0

Merci. Je vais essayer le chemin server.xml. Ma seule préoccupation est que la documentation de Tomcat et d'autres découragent fortement d'aller à server.xml et encouragent META-INF/context.xml – pastafarian

+0

@pastafarian: c'est vrai, mais sur 6.0 je ne l'ai pas pour fonctionner via META-INF, seul le serveur .xml – JoseK

Questions connexes