簡體   English   中英

Spring DispatcherServlet

[英]Spring DispatcherServlet

我有一個使用Spring並具有以下配置的應用程序

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

<mvc:annotation-driven/>
<mvc:resources mapping="/*" location="/" />
<context:component-scan base-package="controller" />

這是整個web.xml文件

<web-app>
<servlet>
    <servlet-name>springrest</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>springrest</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>

該應用程序可以在localhost:8080 / web上很好地運行,但是我想將其更改為localhost:8080 / web / rest,為此,我嘗試將url模式從

<servlet-mapping>
    <servlet-name>springrest</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

<servlet-mapping>
    <servlet-name>springrest</servlet-name>
    <url-pattern>/rest</url-pattern>
</servlet-mapping>

但不幸的是,它不起作用,我在做什么錯?

進行更改后,您會將DispatcherServlet截獲的URL過濾為僅以/rest開頭的URL,而不是以前的所有/ ,因此您只需減少Spring處理的URL數量,而不更改映射。 這不是您想要的,恐怕無法“降級”(從/web/web/rest )帶有某些web.xml配置的Java Web應用程序,您應該在Spring配置中重寫映射( /現在是/rest是什么, /foo現在是/rest/foo )。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM