SPRINGMVC--Configuration details and note descriptions

Source: Internet
Author: User

<?xml version= "1.0" encoding= "UTF-8"? ><beansxmlns= "Http://www.springframework.org/schema/beans" xmlns: Xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:tx= "Http://www.springframework.org/schema/tx" xmlns:  context= "Http://www.springframework.org/schema/context" xmlns:mvc= "Http://www.springframework.org/schema/mvc" xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans-3.0.xsd Http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/ Spring-tx-3.0.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/ Spring-context-3.0.xsdhttp://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/ Spring-mvc-3.0.xsd "> <!--automatically scanned package name---<context:component-scan base-package=" COM.APP,COM.CORE,JUNIT4 " ;</context:component-scan> <!--default annotation mappings Support--<mvc:annotation-driven/> <!--view InterpretationClass--<bean class= "Org.springframework.web.servlet.view.InternalResourceViewResolver" > <property name= " Prefix "value="/web-inf/jsp/"/> <property name=" suffix "value=". JSP "/><!--can be empty, easy to implement their own based on the extension to select the View Interpretation class logic- -<property name= "Viewclass" value= "Org.springframework.web.servlet.view.JstlView"/> </bean> &lt ;! --interceptors--<mvc:interceptors><bean class= "Com.core.mvc.MyInteceptor"/></mvc:interceptors> < !--access scheme for static resource files one (optional)-<mvc:default-servlet-handler/> <!--access to static resource files two (optional)--><mvc:resource S mapping= "/images/**" location= "/images/" cache-period= "31556926"/><mvc:resources mapping= "/js/**" location= "/js/" cache-period= "31556926"/><mvc:resources mapping= "/css/**" location= "/css/" cache-period= "31556926"/  ></beans>


<context:component-scan/> scans the annotations on the classes in the specified package, and the commonly used annotations are:

@Controller declare the action component
@Service     declare Service components      @Service ("Mymovielister")  
@Repository declare DAO components
@Component    refer to components when they are not well categorized.  
@ Requestmapping ("/menu")   Request mapping
@Resource   for injection, (provided by Java EE) by default assembly by name, @Resource (name= "Beanname")  
@Autowired for Injection, (Srping provided)   by type,
@Transactional (Rollbackfor={exception.class}) transaction Management
@ResponseBody   This annotation is used to read the body portion of the request Use the system default configuration of Httpmessageconverter to parse, and then bind the corresponding data to the object to be returned;
@Scope ("prototype")    set the scope of the bean

&NBSP;

<mvc:annotation-driven/> is a shorthand form, Can be manually configured to replace this shorthand form, short form allows beginners to quickly apply the default configuration scheme. <mvc:annotation-driven/> will automatically register defaultannotationhandlermapping and annotationmethodhandleradapter two beans, is required by spring MVC to distribute the request to @controllers.
and provides: data binding support, @NumberFormatannotation support, @DateTimeFormat support, @Valid support, Read-write XML support (JAXB), read and write JSON support.
we used support for JSON when we handled the response to an AJAX request.
when you write JUnit unit tests on an action, from the spring The IOC container takes defaultannotationhandlermapping and annotationmethodhandleradapter two beans, to complete the test, and to know when to take the <MVC: Annotation-driven/> The two beans registered in this sentence.


<mvc:interceptors/> is a shorthand form. By looking at the big picture above, we know that we can configure multiple handlermapping. <mvc:interceptors/> will inject an interceptor for every handlermapping. In fact, we can also manually configure each handlermapping to inject an interceptor.

<mvc:default-servlet-handler/> uses the default servlet to respond to static files.

<mvc:resources mapping= "/images/**" location= "/images/" cache-period= "31556926"/> match url/images/** URLs as static resources , read out in memory by spring and then respond to HTTP


SPRINGMVC--dispatcherservlet Detailed

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

SPRINGMVC--Configuration details and note descriptions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.