我正在使用Spring MVC 3.0上的示例RESTEasy 2.0资源并使用Tomcat 6.我可以通过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 {
...
答案 0 :(得分:6)
您可以在Tomcat server.xml中设置它们。
在<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
的形式访问它