关于spring框架的问题

本人小开发一枚,刚刚入行,这两天写了个spring框架的小demo。web.xml中时这样写的

test
org.springframework.web.servlet.DispatcherServlet

contextConfigLocation
/WEB-INF/cfg/test-servlet.xml



test
*.do

如果我在spring中时通过xml配置和multiActionController来解析请求路径的话是可以找到相关方法的,代码如下
<bean id="paraMethodResolver" class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver">
    <property name="paramName">
        <value>method</value>
    </property>
    <property name="defaultMethodName">
        <value>indexPage</value>
    </property>
</bean>

<bean name="/index.do" class="com.manager.data.TestController">
   <property name="methodNameResolver" ref="paraMethodResolver"></property>
</bean>

class类的代码如下:
public class TestController  extends MultiActionController{
@Autowired
private StudentMapper studentMapper;    
public void indexPage(HttpServletRequest request,HttpServletResponse response){     
List<StudentEntity> student = studentMapper.getStudentAll();   
System.out.println(student.size());

}

}
但是,当我用spring注解注入的时候就不行,
class类代码如下:
@Controller
public class TestController{
@Autowired
private StudentMapper studentMapper;

@RequestMapping("/index.do")
public void indexPage(HttpServletRequest request,HttpServletResponse response){     
List<StudentEntity> student = studentMapper.getStudentAll();   
System.out.println(student.size());
}

}

xml配置如下:

浏览器会报 404 ,控制台报错信息为
警告: No mapping found for HTTP request with URI [/TestMybatis/index.do] in DispatcherServlet with name 'test'

在此想请教诸位大神,为何会出现这种情况。在我的理解里 @RequestMapping不是用来替代MultiActionController的么?两者有什么区别,需要注意什么呢?或者说当我用@Controller注解的时候 在xml除了配置context扫描外还需要做些什么其他事?而且在这过程中我都用到了@Autowired且都有用,这是为何?如何才能让我通过注解来实现前后台访问呢?麻烦了!

你的test-servlet.xml怎么写的?

TestMybatis是项目名?不需要这个吧,直接,ip+端口+/index.do....没发现你代码里有TestMybatis这个映射

spring的配置文件里有配置 context:annotation-config 启动注解?

No mapping found for HTTP request with URI [/TestMybatis/index.do] in DispatcherServlet with name 'test'

必须在test-servlet.xml配置相关的map后才能调用/TestMybatis/index.do

注解哪里应该写@RequestMapping("/index"),不要.do 或者你访问的时候写index.do.do也许也能访问,楼上都是水货,另外求采纳

    <!-- 扫描controller(controller层注入) -->

    <context:component-scan base-package="xxx.controller"
        use-default-filters="false">
        <context:include-filter expression="org.springframework.stereotype.Controller"
            type="annotation" />
    </context:component-scan>

http://blog.csdn.net/u013451048/article/details/52971906
这是我写的一个Spring +SpringMVC+mybatis 框架的deom,你可以参考一下

web.xml代码贴一下