Java EE Advanced (iv) detailed description of spring configuration file

Source: Internet
Author: User

Java EE Advanced (iv) detailed description of spring configuration fileObjective

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:xs    I= "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 "> <!--definition data source using C3P0 connection pool--<bean ID = "DataSource" class= "Com.mchange.v2.c3p0.ComboPooledDataSource" > <!--specify JDBC driver for connection database--&LT;PR        Operty name= "Driverclass" > <value>com.mysql.jdbc.Driver</value> </property> <!--the URL to connect to the database--<property name= "Jdbcurl" > <value>jdbc:mysql://localhost:3          306/eportal?useunicode= true&characterencoding=gbk</value> </property> <!--connect to database user name--<property name= "user" > <value>root</value> </ Property> <!-- Connect the database with a password--<property name= "password" > <value>root</value> </prop Erty> <!--Set the maximum number of connections to a database connection pool-<property name= "Maxpoolsize" > <value>20& Lt;/value> </property> <!--set the minimum number of connections to the database connection pool-<property name= "Minpoolsize" &G              T <value>2</value> </property> <!--set the number of initialization connections for the database connection pool-<property name = "Initialpoolsize" > <value>2</value> </property> <!--Setting the connection to the database connection pool is the most Large idle time in seconds--<property name= "MaxIdleTime" > <value>20</value> </pr operty> </bean> <!--definition Hibernate sessionfactory---<bean id= "sessionfactory" class= "org. Springframework.orm. Hibernate3. Localsessionfactorybean "> <!--Dependency Injection the data source defined above datasource-<property Name= "DataSource" ref= "DataSource"/> <!--registered Hibernate ORM Mapping file--<property name= "Mappingr                  Esources "> <list> <value>com/eportal/ORM/News.hbm.xml</value> <value>com/eportal/ORM/Category.hbm.xml</value> <value>com/eportal/orm/memberle Vel.hbm.xml</value> <value>com/eportal/ORM/Cart.hbm.xml</value> <va Lue>com/eportal/orm/traffic.hbm.xml</value> <value>com/eportal/orm/newsrule.hbm.xml</va Lue> <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 related to Hibernate--<property name= "Hibernateproperties" > <props> <!--set Hibernate database dialect--<prop key= "Hibernate.dialect" >or                  G.hibernate.dialect.mysqldialect</prop> <!--setting hibernate whether to output SQL statements in the console, the development debugging phase is usually set to true-                  <prop key= "Show_sql" >true</prop> <!--settings hibernate maximum number of SQL statements in a commit batch-- <prop key= "Hibernate.jdbc.batch_size" >50</prop> <prop key= "Show_sql" >50&lt ;/prop> </props> </property> </bean> <!--The transaction manager that defines hibernate Hibernat Etransactionmanager--<bean id= "TransactionManager" class= "Org.springframework.orm.hibernate3.Hibern Atetransactionmanager "&GT <!--Dependency Injection sessionfactory---<property name= "sessionfactory" ref= "Sessionfactory"/> </be as defined above An> <!--define Spring's transaction blocker transactioninterceptor-<bean id= "Transactioninterceptor" class= "O Rg.springframework.transaction.interceptor.TransactionInterceptor "> <!--Dependency Injection The transaction manager defined above TransactionManager- <property name= "TransactionManager" ref= "TransactionManager"/> <!--define the methods and transactions that need to be intercepted by the transaction Control type-<property name= "Transactionattributes" > <props> <!--to BR All methods beginning with Owse, list, load, get, and is take the read-only transaction control type--<prop key= "browse*" >propagation_required,readonly&lt ;/prop> <prop key= "list*" >PROPAGATION_REQUIRED,readOnly</prop> <prop K ey= "load*" >PROPAGATION_REQUIRED,readOnly</prop> <prop key= "get*" >propagation_required,read Only</prop> <prop key= "is*" >PROPAGATION_REQUIRED,readOnly</prop> <!--all methods are transacted Control, if no transaction is currently present, create a new transaction--<prop key= "*" >PROPAGATION_REQUIRED</prop> </props&          Gt </property> </bean> <!--define Beannameautoproxycreatorf for spring transactions--<bean class= "org    . Springframework.aop.framework.autoproxy.              Beannameautoproxycreator "> <!--automatically generate a business agent for a specified bean--<property name=" Beannames "> <list> <value>adminService</value> &LT;VALUE&GT;COLUMNSSERVICE&L T;/value> <value>newsService</value> <value>crawlservice</value&                  Gt <value>memberLevelService</value> <value>memberService</value> & Lt;value>categoryservice</value> <valuE>merservice</value> <value>cartService</value> <value>orders service</value> <value>trafficService</value> </list> </              Property> <!--This property is true, indicates that the agent is the target class itself instead of the target class's interface--<property name= "Proxytargetclass" > <value>true</value> </property> <!--Dependency Injection the transaction interceptor defined above Transactionintercepto R--<property name= "Interceptornames" > <list> <value>transac tioninterceptor</value> </list> </property> </bean> <!--assembling common data Library Access Class Basedaoimpl--<bean id= "DAO" class= "Com.eportal.DAO.BaseDAOImpl" > <property name= "sessionf Actory "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> <!--department Department 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= "Da o "/> </bean> <!--Deploy traffic statistics business logic Components Trafficserviceimpl-<bean id=" Trafficservice "class=" Co  M.eportal.service.trafficserviceimpl "> <property name=" DAO "ref=" DAO "/> </bean> <!--  Deploy struts 2 for system user-managed Controllers adminaction-<bean id= "adminaction" class= "Com.eportal.struts.action". Adminaction "scope=" prototype "> <property name=" service "ref=" Adminservice "/> </bean> & lt;! --Deploy Struts 2 controller Columnsactio for news column managementN--<bean id= "columnsaction" class= "Com.eportal.struts.action.ColumnsAction" scope= "prototype" > & Lt;property name= "service" ref= "Columnsservice"/> </bean> <!--deployment Struts 2 Controller for news management newsaction--&gt      ;  <bean id= "newsaction" class= "com.eportal.struts.action. Newsaction "scope=" prototype "> <property name=" service "ref=" Newsservice "/> <property name=      "Columnsservice" ref= "Columnsservice"/> </bean> <!--deployment Struts 2 Controller for news collection rule management crawlaction-  <bean id= "crawlaction" class= "com.eportal.struts.action. Crawlaction "scope=" prototype "> <property name=" service "ref=" Crawlservice "/> <property nam E= "Columnsservice" ref= "Columnsservice"/> </bean> </beans>

American and American pictures



Java EE Advanced (iv) detailed description of spring configuration file

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.