簡體   English   中英

如果不使用擴展名,則在DispatcherServlet中找不到映射

[英]No mapping found in DispatcherServlet without using extension

我收到消息“請求的資源()不可用。” 當轉到使用DispatcherServlet映射的URL時。 以前,當我具有使用.do擴展名的映射設置時,它可以工作,但是當我不使用擴展名進行映射時,它不起作用。

控制器:

@Controller
public class WodServiceController {

    @Autowired
    private WodService wodService;

    @RequestMapping("/json/wod")
    @ResponseBody
    public Word getWord(HttpServletRequest request, HttpServletResponse response) {
        return wodService.getWordOfTheDay();
    }
}

dispatcher-servlet.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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 />
<context:component-scan base-package="foobar.controller" />

<!-- View Resolvers -->

<bean id="defaultViewResolver"
    class="org.springframework.web.servlet.view.InternalResourceViewResolver"
    p:viewClass="org.springframework.web.servlet.view.JstlView"
    p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />

</beans>

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>Services</display-name>
<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        classpath:commonBeans.xml
    </param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/json/*</url-pattern>
</servlet-mapping>

</web-app>

如果我將映射設置為* .do,將RequestMapping設置為wod.do,則可以正常工作。

編輯:

在日志中,當我轉到該URL時會顯示以下消息

在名稱為'dispatcher'的DispatcherServlet中找不到帶有URI [/ foobar / json / wod]的HTTP請求的映射

編輯2:我將alwaysUseFullPath添加到處理程序:

<bean id="annotationHandlerMapping"
    class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
    <property name="alwaysUseFullPath" value="true" />  
</bean>

這是由於我的Apache重定向的設置方式所致。

暫無
暫無

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

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