The role of mvc:annotation-driven annotation
<mvc:annotation-driven> will automatically register two beans, RequestMappingHandlerMapping and RequestMappingHandlerAdapter, which are required for Spring MVC to distribute requests to @Controller , and provide data binding support, @NumberFormatannotation support, @DateTimeFormat support, and @Valid support for reading Features such as support for writing XML (JAXB) and support for reading and writing JSON (default Jackson).
Springmvc-config.xml after using this annotation:
<!-- spring can automatically scan the packages under the base-package or the Java files under the sub-packages, if the scan is related to Spring
Annotated classes, register these classes as Spring beans -->
<context:component-scan base-package="org.fkit.controller"/>
<!--Set configuration scheme-->
<mvc:annotation-driven/>
<!-- Use the default servlet to respond to static files -->
<mvc:default-servlet-handler/>
<!-- View resolver -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 前缀 -->
<property name="prefix">
<value>/WEB-INF/content/</value>
</property>
<!-- 后缀 -->
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
=============================================================
When we use SpringMVC, especially when we are just starting to learn to use it, we often learn from official documents. Write a tag to get SpringMVC. Why???
<mvc:annotation-driven ></mvc:annotation-driven>
- 1
So what did he do? ? Many people do not know yo! ! !
<!--
<mvc:annotation-driven ></mvc:annotation-driven>
-->
<!-- 上面的标签相当于 如下配置-->
<!-- Begin -->
<!-- HandlerMapping -->
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping "></bean>
<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"></bean>
<!-- HandlerAdapter -->
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"></bean>
<bean class="org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter "></bean>
<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"></bean>
<!-- HadnlerExceptionResolvers -->
<bean class="org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver "></bean>
<bean class="org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver"></bean>
<bean class="org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver"></bean>
<!-- End -->
The above configuration also shows that these beans do not need to write name and id attributes. They are provided to DispatcherServlet as types.