Simple parsing of the "Spring" Spring configuration file

Source: Internet
Author: User
Tags aop

A standard spring configuration file Applicationcontext.xml should contain the following basic components: 0, framework configuration

<?xml version= "1.0" encoding= "UTF-8"?> <beans "xmlns=" 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" xmlns: Security= "http://www.springframework.org/schema/security" xsi:schemalocation= "http://www.springframework.org/ Schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd Http://www.springfra Mework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd Http://www.spri NGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/spring-aop-2.5.xsd Http://www.springframe Work.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/s Chema/security HTTP://WWW.SPRINGFRAMEWORK.ORg/schema/security/spring-security-2.0.4.xsd "> <bean></bean> <bean></bean> <-- There can be a lot of bean tags in the back--> </beans>

There will be a lot of configuration: 1, activation configuration

<context:annotation-config/>
"Overview": Activates the spring bean;
The ":<context:annotation-config/>" function is to register the following four beanpostprocessor with the spring container:
Autowiredannotationbeanpostprocessor
Commonannotationbeanpostprocessor
Persistenceannotationbeanpostprocessor
Requiredannotationbeanpostprocessor–>
Used to activate annotations that have been registered in the spring container, either through XML or through package sanning. Each time you configure a applicationcontext.xml file, you can copy it directly into your spring configuration file; 2. Scan configuration

<context:component-scan base-package= "Com.smf.platform,com.smf.pdms"/>
"Summary": Sweep the surface to specify the directory, register to create JavaBean;
"Detailed": In addition to the <context:annotation-config> features,<context:component-scan> can also be scanned under the specified package and register JavaBean Plainly, is to scan you specify the project folder directory, contains @controller, @Service, @RequestMapping and other annotations, and register to create JavaBean @ Each time the Applicationcontext.xml file is configured, the label can be copied directly into its own spring configuration file; 3, Agent configuration

Agent

<aop:aspectj-autoproxy/>

"Summary": Agent
"In detail": Automatically creates proxies for the @aspectj slices in the spring container, weaves the slices, and copies them directly when you configure your own applicationcontext.xml files; 4. read external configuration file configuration

<bean id= "Propertyconfigurer" class= "Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >
        <property name= "Systempropertiesmodename" value= "System_properties_mode_override"/>
        < Property Name= "Ignoreresourcenotfound" value= "true"/>
        <property name= "Locations" >
            <list>
                <value>classpath:jdbc.properties</value>
            </list>
        </property>
</ Bean>

"Summary": Read the external configuration file;
"Detailed": Here the Jdbc.propertie is and SRC peers in the Conf folder configuration file; 5. Data Source Configuration

The data source is your database some connection information, the basic configuration is as follows, the official network I

 <bean id= "Abcdatasource" class= "Org.apache.commons.dbcp.BasicDataSource" destroy-method= "Close" > <property name= "driverclassname" value= "${jdbc.driverclassname}"/> <PR Operty name= "url" value= "${jdbc.url}"/> <property name= "username" value= "${jdbc.username}"/> < Property name= "Password" value= "${jdbc.password}"/> <property name= "maxactive" value= ""/> < Property Name= "Maxidle" value= "/> <property name=" maxwait "value=" 6000 "/> <property name=" t Estonborrow ' value= true '/> <property name= ' defaultautocommit ' value= ' true '/> <property ' name= ' Validationquery "value=" SELECT 1 from dual "/> </bean> 

The contents of the ${} here are key values in the Jdbc.proporities configuration file;
Driverclassname: Drive type name, for example Oracle.jdbc.driver.OracleDriver;
URL: Database address;
Username: Database login name;
Password: Database login password;
Maxactive: The maximum number of active threads in the database connection pool, 0 is unrestricted;
Maxidle: Represents the maximum number of idle;
Maxwait: Maximum wait time, unit millisecond;
Defaultautocommit: whether automatic submission;
Testonborrow:
Validationquery: After the successful connection of the database, with a simple sentence verification query;

There is another way of writing the data source configuration here:

<bean id= "Abcdatasource" class= "Org.apache.commons.dbcp.BasicDataSource" destroy-method= "Close" > <propert
        Y name= "Driverclassname" > <value>${jdbc.driverClassName}</value> </property> <property name= "url" > <value>${jdbc.url}</value> </property> ;p roperty name= "username" > <value>${jdbc.username}</value> </property> &L T;property name= "Password" > <value>${jdbc.password}</value> </property> &  Lt;property name= "maxactive" > <value>150</value> </property> <property Name= "Maxidle" > <value>10</value> </property> <property name= "maxwait
            "> <value>6000</value> </property> <property name=" Testonborrow "> <value>true</value> </property> <property name= "Defaultautocommit" > <value>tr  ue</value> </property> <property name= "Validationquery" > <value>select
 1 from dual</value> </property> </bean>
6, mybatis configuration information
    <!--mybatis Configuration started-->
    <bean id= "sqlsessionfactory" class= "Org.mybatis.spring.SqlSessionFactoryBean" >
        <property name= "DataSource" ref= "Testdatasource"/> <property name= "Configlocation"
        Classpath:mybatis.xml "/>
    </bean>

    <!--auto Scan mapper interface-->
    <bean name=" Testdao "class=" Org.mybatis.spring.mapper.MapperScannerConfigurer ">
        <property name=" basepackage "value=" com.test.**. DAO "/>
        <property name=" sqlsessionfactory ref= "sqlsessionfactory"/>
    </bean>

    < Bean id= "Testtransactionmanager" class= "Org.springframework.jdbc.datasource.DataSourceTransactionManager" >
        <property name= "DataSource" ref= "Testdatasource"/>
    </bean>
    <!--mybatis configuration End-->
7. JPA Configuration

JPA is the abbreviation of the Java Persistence API, the Chinese name Java Persistence Layer API, which is the mapping of JDK 5.0 annotations or XML Description object-relational tables, and persists the entity objects of the runtime into the database. The persistence layer configuration file is typically persistence.xml, and the persistence layer typically configures each type of database, Oracle,sql Server,mysql dialect (dialect) configuration

    <bean id= "Entitymanagerfactory" class= "Org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" >
        <property name= "DataSource" ref= "Abcdatasource"/> <property name=
        "Persistencexmllocation" Value= "Classpath:persistence.xml"/> <property name= "persistenceunitname" value= "Persistenceunit"/>
        <property name= "Jpadialect" ref= "Jpadialect"/>
    </bean>

    <bean id= "Jpadialect" class= " Com.smf.platform.framework.dialect.AbcHibernateJpaDialect "/>

    <bean id=" TransactionManager "class=" Org.springframework.orm.jpa.JpaTransactionManager ">
        <property name=" Entitymanagerfactory ">
            <ref bean= "Entitymanagerfactory"/>
        </property> <property name= "DataSource"
        Smfdatasource "/>
    
8. Transaction Configuration
<bean name= "Transactionattributessource" class= " Org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource "> <property name=" Properties "> <props> <prop key=" get* ">propagation_required,readonly</prop&gt
                ; <prop key= "list*" >PROPAGATION_REQUIRED,readOnly</prop> <prop key= "find*" >propagation_req
                uired,readonly</prop> <prop key= "load*" >PROPAGATION_REQUIRED,readOnly</prop> <prop key= "query*" >PROPAGATION_REQUIRED,readOnly</prop> <prop key= "import*" >propaga
                tion_required,readonly</prop> <prop key= "export*" >PROPAGATION_REQUIRED,readOnly</prop> <prop key= "save*" >PROPAGATION_REQUIRED</prop> <prop key= "submit*" >propaga tion_required</prop> <prop key= "create*" >propagation_required</prop> <prop key= "update*" >PROPAGATION_REQUIRED</prop> <prop key= "
                modify* ">PROPAGATION_REQUIRED</prop> <prop key=" delete* ">PROPAGATION_REQUIRED</prop> <prop key= "remove*" >PROPAGATION_REQUIRED</prop> <prop key= "restore*" >pro pagation_required</prop> <prop key= "do*" >PROPAGATION_REQUIRED</prop> ;p rop key= "execute*" >PROPAGATION_REQUIRED</prop> <prop key= "Debug" >propagation_requires_new </prop> <prop key= "info" >PROPAGATION_REQUIRES_NEW</prop> <prop key= "E Rror ">PROPAGATION_REQUIRES_NEW</prop> <prop key=" Fatal "&GT;PROPAGATION_REQUIRES_NEW&LT;/PROP&G
                T <prop key= "Warn" >PROPAGATION_REQUIRES_NEW</prop> </props> </property> < /bean> 
9, transaction management
    <bean id= "Transactioninterceptor" class= "Org.springframework.transaction.interceptor.TransactionInterceptor" > <property name= "TransactionManager" > <ref bean= "TransactionManager"/> </pr operty> <property name= "Transactionattributesource" > <ref bean= "Transactionattributessourc E "/> </property> </bean> <bean id=" Autotxproxycreator "class=" org.springframework.aop.f 
                Ramework.autoproxy.BeanNameAutoProxyCreator "> <property name=" interceptornames "> <list>
        <idref bean= "Transactioninterceptor"/> </list> </property>  
    <property name= "Beannames" > <value>*Service,*Provider</value> </property> </bean> <bean id= "Simplejdbcdaosupport" class= "Org.springframework.jdbc.core.simple.SimpleJdbc Daosupport "> <proPerty name= "DataSource" ref= "Abcdatasource"/> </bean> <bean id= "DAO" class= "Com.dao.impl.GenericDaoI MPL "> </bean> <bean id=" template "class=" Com.dao.impl.GenericTemplateImpl "> <property Name= "Daosupport" ref= "Simplejdbcdaosupport"/> </bean>

10, Pflogservice Configuration

<bean id= "Pflogservice" class= "Com.smf.platform.log.service.impl.PFLogServiceImpl" >
        <property name= " Appender ">
            <bean class=" Com.smf.platform.log.appender.LogPersistAppender ">
                <property name=" Logownerprovider ">
                    <bean class=" Com.smf.platform.system.service.impl.LogOwnerProviderImpl "></ bean>
                </property>
            </bean>
        </property>
    </bean>

11, other configuration

    <bean id= "Springconfigtool" class= "Com.smf.platform.framework.SpringConfigTool" ></bean>

    < Bean id= "Systemconfig" class= "Com.smf.platform.framework.SystemConfig" ></bean>

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.