Building the SSM Framework Project fundamentals and key configuration files summary

Source: Internet
Author: User
Tags aop config connection pooling file upload xmlns

1.SPRINGMVC is a module of the spring Framework, and SPRINGMVC and spring do not need to be consolidated through an intermediate integration layer. SPRINGMVC is an MVC-based web framework. The idea of MVC is already familiar to everyone, referred to as "Model-view-controller".

The following is a brief introduction of my understanding of SPRING-MVC.


The above figure probably illustrates Springmvc's running process, which may seem a bit foggy, summed up in the following:

The client initiates the request to the front-end controller (dispatcherservlet).

The front-end controller requests handlermappering to find handler, which can be found based on the XML configuration and annotations.

Dispatcherservlet submits the request to the Controller;

After the controller invokes the business logic processing, it returns Modelandview;

Dispatcherservlet queries one or more Viewresoler view resolvers to find the Modelandview specified view;

The view is responsible for displaying the results to the client.

Here is a little explanation of the names and functions of several commonly used components.

Front-end Controller (Dispatcherservlet): For receiving requests, responding to results

Processor Mapper (handlermapping): Find handler based on the requested URL (one of the three core components)

Processor Adapter (Handleradapter): Perform handler according to specific rules (one of the three core components)

Processor (Handler): Write Handler in accordance with handleradapter requirements to do so that the adapter can go to the correct execution Handler

View resolver: Visual analysis (one of the three core components)

View: Includes JSP, PDF, etc.

After understanding the basic principles above, here are the next few major configuration files. The jar packages needed before project development are imported into project projects in advance.


There are several major configuration files that first understand the role of each configuration file.

1. Web. xml: When the service starts, it will first load the Web. XML resource file, which includes the configuration of the front controller, garbled problem, etc.

2.applicatoncontext.xml: General configuration data Sources, things, annotations and so on.

Here I use the form of Applicatoncontext-*.xml to separate the DAO layer, Service layer , Transaction layer so that it is easy to manage

applicatoncontext-dao.xml,applicatoncontext-service.xml, Applicatoncontext-transaction.xml

Configuring the context location in Web. XML when configured separately

3.springmvc.xml: Inside the configuration is the control layer, such as the view resolver static resources, MVC file upload, interceptors and so on. 4. Sqlmapconfig.xml: This configuration file is MyBatis configuration file, there is no need to configure, everything to spring management, but the XML file base configuration to have.


Here is the configuration file code:

Xml

<?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_2_5.xsd "id=" webapp_id "version=" 2.5 "> <display-name>ssm_boot_crm< /display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file >index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file> Default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file> Default.jsp</welcome-file> </welcome-file-list> <!--contextual location--<context-param> <param-na Me>contextconfiglocation</param-name> <param-value>classpath:applicationcontext-*.xml</ Param-value> </context-param> <!--Spring Listener--<listener> &LT;LISTENER-CLASs>org.springframework.web.context.contextloaderlistener</listener-class> </listener> <!-- Post Submission Filter UTF-8-<filter> <filter-name>encoding</filter-name> <filter-class> Org.springframework.web.filter.characterencodingfilter</filter-class> <init-param> <param-name >encoding</param-name> <param-value>UTF-8</param-value> </init-param> </filter> & Lt;filter-mapping> <filter-name>encoding</filter-name> <url-pattern>*.action</ Url-pattern> </filter-mapping> <!--front-end controllers--<servlet> <servlet-name>crm</servlet-nam E> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> < Init-param> <param-name>contextConfigLocation</param-name> <!--here do not configure the default find/web-inf/[servlet-name] -servlet.xml-<param-value>classpath:springmvc.xml</param-value>
		</init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> &lt ;servlet-name>crm</servlet-name> <!--1:*.do *.action intercept requests that end with. Do (does not intercept JSP png jpg. js. css) 2:/ Intercept all requests (do not intercept. JSP) It is recommended to use this method (intercept. Js.css. png) (to release static resources) 3:/* intercept all requests (including. JSP) This way, it is not recommended--<url-pattern>*.acti On</url-pattern> </servlet-mapping> </web-app>


Applicationcontext-dao.xml

<?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:mvc= "Http://www.springframework.org/schema/mvc" xmlns: context= "Http://www.springframework.org/schema/context" xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP" xmlns:tx= "Http://www.springframework.org/schema/tx" xmlns:task= "Http://www.springframework.org/schema/task" xmlns:dubbo= "Http://code.alibabatech.com/schema/dubbo" xsi:schemalocation= "http://www.springframework.org/ Schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/ SCHEMA/MVC http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd http://www.springframework.org/schema/ Context Http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/ SCHEMA/AOP http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.Org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/        
		Task Http://www.springframework.org/schema/task/spring-task-4.0.xsd Http://code.alibabatech.com/schema/dubbo Http://code.alibabatech.com/schema/dubbo/dubbo.xsd > <!--srping Framework profile for managing database connection pooling-<!--configuring Read proper Ties file Db.properties-<context:property-placeholder location= "classpath:db.properties"/> <!--configuration data source for Connect to Database-<bean id= "DataSource" class= "Com.alibaba.druid.pool.DruidDataSource" > <!--database driver-<pro Perty name= "Driverclassname" value= "${jdbc.driver}"/> <!--connection Address--<property name= "url" value= "${jdbc.ur L} "/> <!--username--<property name=" username "value=" ${jdbc.username} "/> <!--password---<pro Perty name= "Password" value= "${jdbc.password}"/> </bean> <!--configuration MyBatis Factory--<bean class= "org.my Batis.spring.SqlSessionFactoryBean > <!--bound data source-<property name= "DataSource" ref= "DataSource"/> <!--configuration MyBatis where the core configuration file is located- <property name= "configlocation" value= "Classpath:SqlMapConfig.xml"/> <!--configuration Pojo aliases--<proper Ty name= "typealiasespackage" value= "Com.company.ssm.crm.pojo"/> </bean> <!--configuration 1: Original DAO development Interface implementation Class Mapper.x ML three x 2: interface development interface does not write implementation class Mapper.xml two (Userdao, Productdao, Branddao ...). ) 3: interface development, and support scanning Cn.itcast.core.dao (Userdao ... ) written under this package can be scanned to-<bean class= "Org.mybatis.spring.mapper.MapperScannerConfigurer" > <property name= "basep Ackage "value=" Com.company.ssm.crm.dao "/> </bean> </beans>


Applicationcontext-service.xml

<?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:mvc= "Http://www.springframework.org/schema/mvc" xmlns: context= "Http://www.springframework.org/schema/context" xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP" xmlns:tx= "Http://www.springframework.org/schema/tx" xmlns:task= "Http://www.springframework.org/schema/task" xmlns:dubbo= "Http://code.alibabatech.com/schema/dubbo" xsi:schemalocation= "http://www.springframework.org/ Schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/ SCHEMA/MVC http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd http://www.springframework.org/schema/ Context Http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/ SCHEMA/AOP http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.Org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/        
		Task Http://www.springframework.org/schema/task/spring-task-4.0.xsd Http://code.alibabatech.com/schema/dubbo Http://code.alibabatech.com/schema/dubbo/dubbo.xsd "> <!--Configure scan package Scan @Service Spring Agent Management business Layer--<cont Ext:component-scan base-package= "Com.company.ssm.crm.service"/> </beans>


Applicationcontext-transaction.xml

<?xml version= "1.0" encoding= "UTF-8"?> <beans xmlns= "Http://www.springframework.org/schema/beans" xmlns: context= "Http://www.springframework.org/schema/context" xmlns:p= "http://www.springframework.org/schema/p" xmlns: aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP" xmlns:tx= "Http://www.springframework.org/schema/tx" 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-4.0.xsd http://www.springframework.org/schema/context http ://www.springframework.org/schema/context/spring-context-4.0.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http ://www.springframework.org/schema/aop/spring-aop-4.0.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/TX/http Www.springframework.org/schema/tx/spring-tx-4.0.xsd Http://www.springframework.org/schema/util/HTTP Www.springframework.org/schema/util/spring-util-4.0.xsd "> <!--Spring transaction Manager--<bean id=" transactionManager "class=" Org.springframework.jdbc.datasource.DataSourceTransactionManager > <!--data Source-<proper Ty name= "DataSource" ref= "DataSource"/> </bean> <!--notifications--<tx:advice id= "Txadvice" Transaction-ma Nager= "TransactionManager" > <tx:attributes> <!--propagation behavior--<tx:method name= "save*" propagation= "R Equired "/> <tx:method name=" insert* "propagation=" REQUIRED "/> <tx:method name=" add* "propagation=" REQU IRED "/> <tx:method name=" create* "propagation=" REQUIRED "/> <tx:method name=" delete* "propagation=" REQU IRED "/> <tx:method name=" update* "propagation=" REQUIRED "/> <tx:method name=" find* "propagation=" SUPPOR TS "read-only=" true "/> <tx:method name=" select* "propagation=" SUPPORTS "read-only=" true "/> <tx:method Name= "get*" propagation= "SUPPORTS" read-only= "true"/> </tx:attributes> </tx:advice> <!--AOP Facets- <aop:config>
		<aop:advisor advice-ref= "Txadvice" pointcut= "Execution (* cn.itcast.core.service.*.* (..))"/> </aop:config&
	
Gt </beans>



Springmvc.xml

<beans xmlns= "Http://www.springframework.org/schema/beans" xmlns:xsi= "http://www.w3.org/2001/ Xmlschema-instance "xmlns:mvc=" Http://www.springframework.org/schema/mvc "xmlns:context="/HTTP/ Www.springframework.org/schema/context "xmlns:aop=" HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP "xmlns:tx="/HTTP/ Www.springframework.org/schema/tx "xmlns:task=" Http://www.springframework.org/schema/task "xmlns:dubbo="/HTTP/ Code.alibabatech.com/schema/dubbo "xsi:schemalocation=" Http://www.springframework.org/schema/beans/http Www.springframework.org/schema/beans/spring-beans-4.0.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/MVC/HTTP Www.springframework.org/schema/mvc/spring-mvc-4.0.xsd Http://www.springframework.org/schema/context/HTTP Www.springframework.org/schema/context/spring-context-4.0.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP/HTTP Www.springframework.org/schema/aop/spring-aop-4.0.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/TX/HTTP www.springframework.oRg/schema/tx/spring-tx-4.0.xsd Http://www.springframework.org/schema/task http://www.springframework.org/schema/ Task/spring-task-4.0.xsd Http://code.alibabatech.com/schema/dubbo Http://code.alibabatech.com/schema/dubbo/dub Bo.xsd "> <!--Load Properties file--<context:property-placeholder location=" classpath:resource.properties "/> &lt ;! --Configuration Scanner--<context:component-scan base-package= "Com.company.ssm.crm.controller"/> <!--Configuring processor Mapper Adapter--&
	Gt <mvc:annotation-driven/> <!--configuration View interpreter JSP--<bean id= "Jspviewresolver" class= "ORG.SPRINGFRAMEWORK.W Eb.servlet.view.InternalResourceViewResolver "> <property name=" prefix "value="/web-inf/jsp/"/> < Property name= "suffix" value= ". jsp"/> </bean> </beans>


Sqlmapconfig.xml

<beans xmlns= "Http://www.springframework.org/schema/beans" xmlns:xsi= "http://www.w3.org/2001/ Xmlschema-instance "xmlns:mvc=" Http://www.springframework.org/schema/mvc "xmlns:context="/HTTP/ Www.springframework.org/schema/context "xmlns:aop=" HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP "xmlns:tx="/HTTP/ Www.springframework.org/schema/tx "xmlns:task=" Http://www.springframework.org/schema/task "xmlns:dubbo="/HTTP/ Code.alibabatech.com/schema/dubbo "xsi:schemalocation=" Http://www.springframework.org/schema/beans/http Www.springframework.org/schema/beans/spring-beans-4.0.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/MVC/HTTP Www.springframework.org/schema/mvc/spring-mvc-4.0.xsd Http://www.springframework.org/schema/context/HTTP Www.springframework.org/schema/context/spring-context-4.0.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP/HTTP Www.springframework.org/schema/aop/spring-aop-4.0.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/TX/HTTP www.springframework.oRg/schema/tx/spring-tx-4.0.xsd Http://www.springframework.org/schema/task http://www.springframework.org/schema/ Task/spring-task-4.0.xsd Http://code.alibabatech.com/schema/dubbo Http://code.alibabatech.com/schema/dubbo/dub Bo.xsd "> <!--Load Properties file--<context:property-placeholder location=" classpath:resource.properties "/> &lt ;! --Configuration Scanner--<context:component-scan base-package= "Com.company.ssm.crm.controller"/> <!--Configuring processor Mapper Adapter--&
	Gt <mvc:annotation-driven/> <!--configuration View interpreter JSP--<bean id= "Jspviewresolver" class= "ORG.SPRINGFRAMEWORK.W Eb.servlet.view.InternalResourceViewResolver "> <property name=" prefix "value="/web-inf/jsp/"/> < Property name= "suffix" value= ". jsp"/> </bean> </beans>


Db.properties

Jdbc.driver=com.mysql.jdbc.driver
Jdbc.url=jdbc:mysql://localhost:3306/crm?characterencoding=utf-8
Jdbc.username=root
Jdbc.password=root



The above is the configuration of the main configuration files, especially in the Web. XML, the default load of resource files in the Web_inf directory, if you are not in the XML, you should write a clear file path, such as writing in the SRC directory will write classpath, before the development process ignored this , so startup has been an error to find the resource file.

Main sources of reference

and combined with their own SSM building, summary SSM environment to build, so that memory, communication and learning, what is wrong place, welcome correction, communication


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.