0

我是春天的新手,因此也许我的问题很愚蠢!我正在尝试将控制器添加到 Spring 的 Petclinic 示例中。但是,此控制器中的映射不起作用,我收到 404 错误。我将相同的映射添加到其他现有控制器并且它可以工作。我想看看我做错了什么。这是我的控制器:

package org.springframework.samples.petclinic.web;

import java.util.Map;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.stereotype.Controller;

@Controller
public class TwitterController {

    @RequestMapping(value = "/twitter/searchtweets", method = RequestMethod.GET)
        public String initFindForm(Map<String, Object> model) {
        ...
        return "twitter/searchtweets";
    }
}

这是我的 MVC 配置文件中的组件扫描定义:

<context:component-scan
        base-package="org.springframework.samples.petclinic.web"/>

和:

    <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
    <property name="contentNegotiationManager" ref="cnManager"/>

    <property name="viewResolvers">
        <list>
             <!-- Default viewClass: JSTL view (JSP with html output) -->
            <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                <!-- Example: a logical view name of 'vets' is mapped to '/WEB-INF/jsp/vets.jsp' -->
                <property name="prefix" value="/WEB-INF/jsp/"/>
                <property name="suffix" value=".jsp"/>
            </bean>

            <!-- Used here for 'xml' and 'atom' views  -->
            <bean class="org.springframework.web.servlet.view.BeanNameViewResolver"/>
        </list>
    </property>
</bean>

<!-- Simple strategy: only path extension is taken into account -->
<bean id="cnManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
    <property name="favorPathExtension" value="true"/>
    <property name="ignoreAcceptHeader" value="true"/>
    <property name="defaultContentType" value="text/html"/>

    <property name="mediaTypes">
        <map>
            <entry key="html" value="text/html" />
            <entry key="xml" value="application/xml" />
            <entry key="atom" value="application/atom+xml" />
        </map>
    </property>
</bean>

地址:localhost:8081/petclinic/twitter/searchtweets.html返回404错误。值得一提的是这里的jsp文件:webapp/WEB_INF/jsp/twitter/searchtweets.jsp

我错过了什么吗?

4

0 回答 0