Features of the Springmvc.xml and Applicationcontext.xml configurations

Source: Internet
Author: User

1:springmvc.xml Configuration Essentials

generally it mainly configures the controller's component Scanner and view resolver

Below is: Springmvc.xml file

<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "Http://www.springframework.org/schema/beans" xmlns: Xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:p= "http://www.springframework.org/schema/p" xmlns:context= "Http://www.springframework.org/schema/context" xmlns:mvc= "Http://www.springframework.org/schema/mvc" Xmlns:task         = "Http://www.springframework.org/schema/task" xsi:schemalocation= "Http://www.springframework.org/schema/beans Http://www.springframework.org/schema/beans/spring-beans-4.2.xsd Http://www.springframework.org/schema/cont Ext http://www.springframework.org/schema/context/spring-context-4.2.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SC HEMA/MVC http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd Http://www.springframework.org/schem A/task http://www.springframework.org/schema/task/spring-task-4.2.xsd "> <!--use annotation development without configuring C      Ontroller, you need to configure a component scanner--    <context:component-scan base-package= "Com.edu.test.controller"/> <!--view Resolver-- <bean class= "Org.springframework.web.servlet.view.InternalResourceViewResolver" > <!--configuration from the project root directory to the specified target Recording one end of the path, it is recommended to specify a shallow directory--<property name= "prefix" value= "/web-inf/jsp/" ></property> <!-  -filename suffix---<property name= "suffix" value= ". jsp" ></property> </bean></beans>

2:applicationcontext.xml Configuration Essentials (requires <listener> in Web. xml file)

Below is: Applicationcontext.xml file

<beans xmlns= "Http://www.springframework.org/schema/beans" xmlns:xsi= "http://www.w3.org/2001/ Xmlschema-instance "xmlns:context=" Http://www.springframework.org/schema/context "xmlns:aop="/HTTP/ Www.springframework.org/schema/aop "xmlns:tx=" http://www.springframework.org/schema/tx "xsi:schemalocation=" http ://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd htt       P://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http ://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd "> <!--configuration group Scanner, developed using annotations, without the need to configure DAO and service-
<!--This property can also be configured in the Springmvc.xml file--<context:component-scan base-package= "Com.edu.test"/> <!--data Source-<bean id= "DataSource" class= "Org.springframework.jdbc.datasource.DriverManagerDataSource" > <property name= "driverclassname" value= "Com.mysql.jdbc.Driver"/> <property name= "url" value= " Jdbc:mysql://localhost:3306/test "/> <property name=" username "value=" root "/> <property name=" p Assword "value=" "/> </bean> <!--configuration Session factory--<bean id=" sqlsessionfactory "class=" org.m Ybatis.spring.SqlSessionFactoryBean "> <property name=" dataSource "ref=" DataSource "/> <property N Ame= "Configlocation" value= "Classpath:mybatis-config.xml"/> </bean> <!--transaction Manager--<bean ID = "TransactionManager" class= "Org.springframework.jdbc.datasource.DataSourceTransactionManager" > <property Name= "DataSource" ref= "dataSource "/> </bean> <!--configuring AOP notifications--<tx:advice id=" Txadvice "transaction-manager=" Transactio Nmanager > <!--Configuring Transaction Properties--<tx:attributes> <!--adding transaction management methods-- <tx:method name= "save*" propagation= "REQUIRED"/> <tx:method name= "delete*" propagation= "REQUIRED"/&G T <tx:method name= "update*" propagation= "REQUIRED"/> <tx:method name= "select*" read-only= "true"/> </tx:attributes> </tx:advice> <!--Configure AOP, configure AOP-to-add transaction management operations--<aop:config> <!--introduced a spring-defined transaction notification that needs to be aop:advisor---<!--under hard-----<aop:advisor advice-ref= "Txadvice "Pointcut=" Execution (* com.edu.test.service.*.* (..)) " /> </aop:config></beans>

3: In the Web. xml file, bring Springmvc.xml and Applicationcontext.xml together

Below is: WEB.XM file

<?xml version= "1.0" encoding= "UTF-8"? ><web-app xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns= "Http://java.sun.com/xml/ns/javaee" xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee/http Java.sun.com/xml/ns/javaee/web-app_3_0.xsd "id=" webapp_id "version=" 3.0 "> <!--Configuration Listener--&LT;LISTENER&GT        ; <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </ listener> <context-param> <param-name>contextConfigLocation</param-name> <param-v Alue>classpath:applicationcontext.xml</param-value> </context-param> <!--Central Controller--< Servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web. Servlet. Dispatcherservlet</servlet-class> <init-param> <param-name>contextconfiglocation</p Aram-name> &LT;PARAM-VALUE&GT;CLAsspath:springmvc.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapp Ing> <!--Configure spring-provided character encoding filters--<filter> &LT;FILTER-NAME&GT;SPRINGCHARACTERENCODINGFI Lter</filter-name> <filter-class>org.springframework.web.filter.characterencodingfilter</ filter-class> <init-param> <param-name>encoding</param-name> <param-v alue>utf-8</param-value> </init-param> </filter> <filter-mapping> <filte R-name>springcharacterencodingfilter</filter-name> <url-pattern>*.do</url-pattern> </fil Ter-mapping></web-app>

Features of the Springmvc.xml and Applicationcontext.xml configurations

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.