MYBATIS,SPRING,SPRINGMVC three-frame SSM integration Template

Source: Internet
Author: User

Integration steps

    • Create a Web project
    • Import all the jar packages required for consolidation
    • Write the required configuration files for each layer

1) MyBatis Global configuration file

<configuration>

<!--batch alias settings--
<typeAliases>
<package name= "Cn.ssm.pojo"/>
</typeAliases>

</configuration>

2) Spring Management MyBatis configuration file

<!--loading external resource files--
<context:property-placeholder location= "Classpath:db.properties"/>

<!--managing Data sources--
<bean id= "DataSource" class= "Org.apache.commons.dbcp.BasicDataSource" >
<property name= "Driverclassname" value= "${jdbc.driver}"/>
<property name= "url" value= "${jdbc.url}"/>
<property name= "username" value= "${jdbc.username}"/>
<property name= "Password" value= "${jdbc.password}"/>
</bean>

<!--management Sqlsessionfactory--
<bean id= "Sqlsessionfactory" class= "Org.mybatis.spring.SqlSessionFactoryBean" >
<!--injecting data sources--
<property name= "DataSource" ref= "DataSource"/>
<!--load the global configuration file for MyBatis--
<property name= "configlocation" value= "Classpath:mybatis/sqlmapconfig.xml"/>
</bean>

<!--managing bulk agent Objects--
<bean class= "Org.mybatis.spring.mapper.MapperScannerConfigurer" >
<!--Scan Package--
<property name= "Basepackage" value= "Cn.ssm.mapper"/>
</bean>

3) Manage Service

<!--Manage all service--
<context:component-scan base-package= "Cn.ssm.service"/>

4) Management Services

<!--configuration Transaction Manager-
<bean id= "TransactionManager" class= "Org.springframework.jdbc.datasource.DataSourceTransactionManager" >
<!--injecting data sources--
<property name= "DataSource" ref= "DataSource"/>
</bean>

<!--notice--
<tx:advice id= "Txadvice" transaction-manager= "TransactionManager" >
<tx:attributes>
<tx:method name= "insert*" propagation= "REQUIRED"/>
<tx:method name= "update*" propagation= "REQUIRED"/>
<tx:method name= "delete*" propagation= "REQUIRED"/>

<tx:method name= "query*" propagation= "SUPPORTS" read-only= "true"/>
</tx:attributes>
</tx:advice>

<!--configuring AOP--
<aop:config>
<aop:advisor advice-ref= "Txadvice" pointcut= "Execution (* cn.ssm.service.*.* (..))" />
</aop:config>

5) SPRINGMVC's core configuration file

<!--1, configure the scanner, scan the annotated class with @controller and be maintained by the Spring bean container-
<context:component-scan base-package= "Cn.ssm.controller"/>
<!--2, note driver: Simple configuration, can load type converter, validator, JSON parser--
<mvc:annotation-driven conversion-service= "Conversionservice"/>
<!--Configuration type converters--
<bean id= "Conversionservice" class= "Org.springframework.context.support.ConversionServiceFactoryBean" >
<property name= "Converters" >
<set>
<bean class= "Cn.ssm.utils.converter.CustomParamsConverter"/>
</set>
</property>
</bean>
<!--3, configure view resolver--
<bean class= "Org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name= "prefix" value= "/web-inf/jsp/"/>
<property name= "suffix" value= ". jsp"/>
</bean>
<!--4, load other configuration files--
<import resource= "Classpath:spring/applicationcontext-*.xml"/>

6) Web. xml file

<!--Configure the SPRINGMVC Front Controller--
<servlet>
<servlet-name>ssm</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!--load Springmvc's core profile--
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/springmvc.xml</param-value>
</init-param>
<!--initialize the SPRINGMVC framework with the Web container started--
<load-on-startup>1</load-on-startup>
</servlet>

<!--Configure access-blocking URLs .action-->
<servlet-mapping>
<servlet-name>ssm</servlet-name>
<!--*.action: Block all URLs ending with action/: Yes, SPRINGMVC restful style struts2:/*: Block all (JSP 404)--
<url-pattern>*.action</url-pattern>
</servlet-mapping>

<!--Configure garbled filters--
<filter>
<filter-name>CharacterEncodingFilter</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>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

    • Introducing Resource Files
    1. Connection Database Information Profile Db.properties
    2. Log file Log4j.properties

MYBATIS,SPRING,SPRINGMVC three-frame SSM integration Template

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.