Turn: <mvc:annotation-driven/> annotation meaning

<mvc:annotation-driven /> is a shorthand form, which can be completely replaced by manual configuration. The shorthand form allows beginners to quickly apply the default configuration scheme. <mvc:annotation-driven /> will automatically register two beans, DefaultAnnotationHandlerMapping and AnnotationMethodHandlerAdapter, which are necessary for spring MVC to distribute requests to @Controllers.
And provides: data binding support, @NumberFormatannotation support, @DateTimeFormat support, @Valid support, support for reading and writing XML (JAXB), support for reading and writing JSON (Jackson).
Later, when we process the response to the ajax request, we use the support for json.
Later, when writing a JUnit unit test for an action, you need to take the DefaultAnnotationHandlerMapping and AnnotationMethodHandlerAdapter beans from the spring IOC container to complete the test. When taking it, you must know that the two beans registered by the sentence <mvc:annotation-driven /> .

 

<context:annotation-config> declares support for general annotations such as @Required@Autowired@PostConstruct, and so on.

<mvc:annotation-driven /> is actually rather pointless. It declares explicit support for annotation-driven MVC controllers (i.e.@RequestMapping@Controller, etc), even though support for those is the default behaviour.

My advice is to always declare <context:annotation-config>, but don't bother with <mvc:annotation-driven /> unless you want JSON support via Jackson.

When we need the controller to return a map json object, we can set <mvc:annotation-driven />,

Also set the <mvc:message-converters> tag, set the character set and json processing class

Original address: http://kingliu.iteye.com/blog/1972973

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325250144&siteId=291194637