是什么缘由形成这种区别的呢?为何一开始没用<mvc:annotation-driven/>的时候能够,添加了默认servlet以后就不行了呢?
html
------------------------------------------------java
This tag registers the DefaultAnnotationHandlerMapping and AnnotationMethodHandlerAdapter beans that are required for Spring MVC to dispatch requests to Controllers.
这个标签注册了Spring MVC分发请求到控制器所必须的DefaultAnnotationHandlerMapping和AnnotationMethodHandlerAdapter实例web
The tag configures those two beans with sensible defaults based on what is present in your classpath.
标签配置的这2个实例能够根据classpath中的内容默认提供如下功能:spring
The defaults are:
1. Support for Spring 3's Type ConversionService in addition to JavaBeans PropertyEditors during Data Binding.
A ConversionService instance produced by the org.springframework.format.support.FormattingConversionServiceFactoryBean is used by default.
This can be overriden by setting the conversion-service attribute.
支持spring3的javaBeans属性编辑器数据绑定时的类型转换服务。
类型转换服务实例默认为org.springframework.format.support.FormattingConversionServiceFactoryBean。
能够覆盖conversion-service属性来指定类型转换服务实例类。json
2. Support for formatting Number fields using the @NumberFormat annotation
支持@NumberFormat 注解格式化数字类型字段。spring-mvc
3. Support for formatting Date, Calendar, Long, and Joda Time fields using the @DateTimeFormat annotation, if Joda Time 1.3 or higher is present on the classpath.
@DateTimeFormat注解格式化 Date, Calendar, Long和 Joda Time(如classpath下存在Joda Time 1.3或更高版本)字段mvc
4. Support for validating @Controller inputs with @Valid, if a JSR-303 Provider is present on the classpath.
The validation system can be explicitly configured by setting the validator attribute.
支持@Valid注解验证控制器数据,classpath中需JSR-303的**。
可使用setting明确的配置app
5. Support for reading and writing XML, if JAXB is present on the classpath.
支持读写xml,classpath中需JAXB 。编辑器
6. Support for reading and writing JSON, if Jackson is present on the classpath.
支持读写json,classpath中需Jackson 。ide
A typical usage is shown below:
下边是用法:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
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/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<!-- JSR-303 support will be detected on classpath and enabled automatically -->
<mvc:annotation-driven/>
</beans>
求上述1-6的使用例子。
总结:
要使用spring mvc中的@Controller注解,就必需要配置<mvc:annotation-driven />,不然org.springframework.web.servlet.DispatcherServlet没法找到控制器并把请求分发到控制器。
转自:http://www.iteye.com/problems/66133
http://www.noday.net/articles/2011/08/27/1314458126911.html