ssm integrates spring with basic configuration

Personal understanding + reference summary, if there are any mistakes, please put forward, thank you!


Configure namespaces: namespaces correspond to schema documents one-to-one, and there are several schema documents (.xsd) for several namespaces.

1. Configure PropertyPlaceholderConfigurer: Read the configuration file.
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">    
<property name="location"> <value>classpath*: jdbc.properties</value>
</property>
</ bean>
Reference: http://www.cnblogs.com/dream-to-pku/p/6367396.html

2. Automatic scanning of configuration annotations: <context:component-scan>
    If scanned @Reposity @Controller @Service etc. These annotated classes are registered as beans.
    <context:component-scan> has a use-default-filters attribute with a value of true by default.
    In addition, <context:annotation-config/> also provides two subtags <context:include-filter> and <context:exclude-filter>
    In the case of Use-dafault-filters=false, <context:exclude-filter> specifies Do not scan, scan specified by <context:include-filter>.
    In the case of use-default-filters=true, all annotation classes under the specified package are scanned by default, and the package specified by <context:exclude-filter> is not scanned.
Reference: http://www.cnblogs.com/youngjoy/p/3817471.html

3. Configure data source

Reference : http://blog.csdn.net/yangyz_love/article/details/8199207
4. Configure SqlSessionFactoryBean (SqlSessionFactoryBean is The role of a factory bean is to parse the configuration (data source, alias, etc.)
    In MyBatis, use SqlSessionFactoryBuilder to create SqlSessionFactory, and then create SqlSession. Once you have a session, you can use it to execute map statements, commit or rollback connections, and finally, when you no longer need it, you can close the session.
After the framework is integrated, SqlSessionFactoryBean will be used instead of SqlSessionFactoryBuilder to create SqlSessionFactory.
Reference: http://fhd001.iteye.com/blog/1125528
      http://blog.csdn.net/liuxiao723846/article/details/52424802
     
5. Configure MapperScannerConfigurer
   MapperScannerConfigurer will automatically scan all interface classes under the package specified by basePackage (including subclasses), if they are defined in the SQL mapping file, they are dynamically defined as a Spring Bean, so that we can directly inject the beans of the mapped interface in the Service.
   If they are defined in the SQL mapping file, they are dynamically defined as a Spring Bean: I personally understand that the interface class is mapped by nameSpace in xml and compiled into a class with methods for implementing database operations. Equivalent to the method of the previous dao layer.
Reference: http://blog.csdn.net/u011318776/article/details/52819241


6. Configure transaction DataSourceTransactionManager

7. Configure facet <aop:config>
|The first * - wildcard random return value type | 
| The second * —— The random class under the wildcard package com.joinsoft.service| 
|The third * —— The random method of the random class under the wildcard package com.joinsoft.service| 
|The first four.. -- wildcard methods can have 0 or more arguments | 
<aop:config expose-proxy="true">
<aop:pointcut id="txPointcut"
      expression="execution(* com.joinsoft.service.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut" />
</aop:config>
    

Guess you like

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