Transferred from: http://book.51cto.com/art/201004/193743.htm
Here is a detailed explanation of spring2.5 's implementation principle, which is very useful.
The spring configuration file is a "sheet" that guides the Spring factory for bean production, Dependency injection (assembly), and bean instance distribution. Java EE programmers must learn and flexibly apply this "drawing" to accurately express their "production intentions". The spring configuration file is one or more standard XML documents, and Applicationcontext.xml is the default profile for spring, and will attempt to load the default configuration file when the container is started without the specified configuration document.
The following is a more complete configuration file template, the basic purpose of the XML tag node in the document also gives a detailed explanation, these XML tag nodes in the subsequent knowledge points will be used, proficiency in the use of these XML nodes and attributes, for our hands-on writing configuration files to lay a solid foundation.
Here is an example of the above configuration:
<?xml version= "1.0" encoding= "UTF-8"?>
<beans xmlns= "Http://www.springframework.org/schema/beans"
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-2.5.xsd ">
<!--define a data source that uses the C3P0 connection pool--
<bean id= "DataSource" class= "Com.mchange.v2.c3p0.ComboPooledDataSource" >
<!--Specify the JDBC driver to connect to the database
<property name= "Driverclass" >
<value>com.mysql.jdbc.Driver</value>
</property>
<!--the URL used to connect to the database--
<property name= "Jdbcurl" >
<value>jdbc:mysql://localhost:3306/eportal?useunicode=
True&characterencoding=gbk</value>
</property>
<!--user name to connect to the database--
<property name= "User" >
<value>root</value>
</property>
<!--connect the database with a password--
<property name= "Password" >
<value>root</value>
</property>
<!--set the maximum number of connections to a database connection pool-
<property name= "Maxpoolsize" >
<value>20</value>
</property>
<!--set the minimum number of connections to the database connection pool--
<property name= "Minpoolsize" >
<value>2</value>
</property>
<!--set the number of initialization connections for the database connection pool--
<property name= "Initialpoolsize" >
<value>2</value>
</property>
<!--set the maximum idle time for connections to a database connection pool in seconds--
<property name= "MaxIdleTime" >
<value>20</value>
</property>
</bean>
<!--define Hibernate sessionfactory--
<bean id= "Sessionfactory"
Class= "Org.springframework.orm.
Hibernate3. Localsessionfactorybean ">
<!--relies on injecting the data source defined above DataSource
<property name= "DataSource" ref= "DataSource"/>
<!--an ORM mapping file that registers hibernate--
<property name= "Mappingresources" >
<list>
<value>com/eportal/ORM/News.hbm.xml</value>
<value>com/eportal/ORM/Category.hbm.xml</value>
<value>com/eportal/ORM/Memberlevel.hbm.xml</value>
<value>com/eportal/ORM/Cart.hbm.xml</value>
<value>com/eportal/ORM/Traffic.hbm.xml</value>
<value>com/eportal/ORM/Newsrule.hbm.xml</value>
<value>com/eportal/ORM/Merchandise.hbm.xml</value>
<value>com/eportal/ORM/Admin.hbm.xml</value>
<value>com/eportal/ORM/Orders.hbm.xml</value>
<value>com/eportal/ORM/Cartselectedmer.hbm.xml</value>
<value>com/eportal/ORM/Newscolumns.hbm.xml</value>
<value>com/eportal/ORM/Member.hbm.xml</value>
</list>
</property>
<!--set properties for Hibernate-
<property name= "Hibernateproperties" >
<props>
<!--setting up Hibernate database dialect---
<prop key= "Hibernate.dialect" >org.hibernate.dialect.MySQLDialect</prop>
<!--setting Hibernate to output SQL statements in the console, the development debugging phase is usually set to true-
<prop key= "Show_sql" >true</prop>
<!--set the maximum number of SQL statements in a commit batch for hibernate--
<prop key= "Hibernate.jdbc.batch_size" >50</prop>
<prop key= "Show_sql" >50</prop>
</props>
</property>
</bean>
<!--define Hibernate's transaction manager Hibernatetransactionmanager
<bean id= "TransactionManager"
class= "Org.springframework.orm.hibernate3.HibernateTransactionManager" >
<!--relies on injecting the sessionfactory defined above--
<property name= "Sessionfactory" ref= "Sessionfactory"/>
</bean>
<!--define Spring's transaction interceptor Transactioninterceptor
<bean id= "Transactioninterceptor"
class= "Org.springframework.transaction.interceptor.TransactionInterceptor" >
<!--Dependency injection on the transaction manager defined above TransactionManager
<property name= "TransactionManager" ref= "TransactionManager"/>
<!--defines the method to be used for transaction interception and the type of transaction control adopted--
<property name= "Transactionattributes" >
<props>
<!--all methods starting with browse, list, load, get, and is read-only transaction control type-
<prop key= "browse*" >PROPAGATION_REQUIRED,readOnly</prop>
<prop key= "list*" >PROPAGATION_REQUIRED,readOnly</prop>
<prop key= "load*" >PROPAGATION_REQUIRED,readOnly</prop>
<prop key= "get*" >PROPAGATION_REQUIRED,readOnly</prop>
<prop key= "is*" >PROPAGATION_REQUIRED,readOnly</prop>
<!--all methods are transaction controlled, and if there is no transaction, create a new transaction-
<prop key= "*" >PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<!--define Beannameautoproxycreatorf for spring transactions--
<bean
Class= "Org.springframework.aop.framework.autoproxy.
Beannameautoproxycreator ">
<!--automatically generate a business agent for the specified bean--
<property name= "Beannames" >
<list>
<value>adminService</value>
<value>columnsService</value>
<value>newsService</value>
<value>crawlService</value>
<value>memberLevelService</value>
<value>memberService</value>
<value>categoryService</value>
<value>merService</value>
<value>cartService</value>
<value>ordersService</value>
<value>trafficService</value>
</list>
</property>
<!--This property is true, it means that the proxy is the target class itself rather than the target class's interface--
<property name= "Proxytargetclass" >
<value>true</value>
</property>
<!--Dependency injection of the transaction interceptor defined above Transactioninterceptor--
<property name= "Interceptornames" >
<list>
<value>transactionInterceptor</value>
</list>
</property>
</bean>
<!--assembling Universal Database access class Basedaoimpl
<bean id= "DAO" class= "Com.eportal.DAO.BaseDAOImpl" >
<property name= "Sessionfactory" ref= "Sessionfactory"/>
</bean>
<!--deployment System user management business logic Components Adminserviceimpl
<bean id= "Adminservice" class= "Com.eportal.service.AdminServiceImpl" >
<property name= "DAO" ref= "DAO"/>
</bean>
<!--deploy news column management business logic components Columnsserviceimpl--
<bean id= "Columnsservice" class= "Com.eportal.service.ColumnsServiceImpl" >
<property name= "DAO" ref= "DAO"/>
</bean>
<!--deploy order management business logic Components Orderserviceimpl
<bean id= "Ordersservice" class= "Com.eportal.service.OrderServiceImpl" >
<property name= "DAO" ref= "DAO"/>
</bean>
<!--deploying traffic statistics business logic components Trafficserviceimpl--
<bean id= "Trafficservice" class= "Com.eportal.service.TrafficServiceImpl" >
<property name= "DAO" ref= "DAO"/>
</bean>
<!--deploy struts 2 Controller for System user management Adminaction--
<bean id= "adminaction" class= "com.eportal.struts.action.
Adminaction "
Scope= "Prototype" >
<property name= "service" ref= "Adminservice"/>
</bean>
<!--deploy struts 2 Controller for news column Columnsaction--
<bean id= "columnsaction" class= "com.eportal.struts.action.
Columnsaction "
Scope= "Prototype" >
<property name= "service" ref= "Columnsservice"/>
</bean>
<!--deployment Struts 2 Controller for news management Newsaction--
<bean id= "newsaction" class= "com.eportal.struts.action.
Newsaction "
Scope= "Prototype" >
<property name= "service" ref= "Newsservice"/>
<property name= "Columnsservice" ref= "Columnsservice"/>
</bean>
<!--deploy struts 2 Controller for news collection rules Crawlaction--
<bean id= "crawlaction" class= "com.eportal.struts.action.
Crawlaction "
Scope= "Prototype" >
<property name= "service" ref= "Crawlservice"/>
<property name= "Columnsservice" ref= "Columnsservice"/>
</bean>
</beans>
A detailed description of the spring configuration file