Spring3 MVC - 控制器类被调用,但不是控制器方法。
控制器:
package com.quizat.controller;
@Controller
public class QuizatController {
public QuizatController(){
System.out.println("in controller");
}
@RequestMapping("/")
@ResponseBody
public String home(Model model) throws Exception {
System.out.println("home is running");
return "success";
}
}
我的 web.xml
<display-name>Spring3Example</display-name>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
我的调度程序-servlet.xml
<mvc:annotation-driven />
<context:annotation-config />
<context:component-scan base-package="com.quizat" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass">
<value>org.springframework.web.servlet.view.JstlView</value>
</property>
<property name="prefix">
<value>/view/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
我的控制器的构造函数运行。但是我在 Controller 中的方法没有被调用。我犯了什么错误?