Next to the previous blog, this blog we introduce the last--spring of SSH. In SSH, struts is a front-end framework, and Hibernate is a framework for dealing with databases, so what about spring? Spring is a framework for managing struts and hibernate. So how exactly is it managed?
In general, struts calls the service layer's method, and if it doesn't use spring, it needs to be a new object to invoke this method. If you use spring, you can have the new object as a struts action property, by spring to instantiate, that is, the instantiation process is given to spring to deal with, so we omit a new process, directly to spring processing, We can use it directly when we call the method. The same is true of Spring's management of Hibernate, where Spring's IOC container injects the resources needed for action, and the creation and transaction management of the session that manages struts and hibernate,hibernate is given to spring.
Today this blog is still to introduce spring as the main, so as to how spring is the role of container management, our next blog SSH integration will specify, here we simply mention, is to let us have a macro understanding of spring, Roughly know what kind of position spring is in ssh and what kind of role it can play.
All right, let's get to the point here and explain how to configure spring.
We still follow one of these steps: Jar package and configuration file Applicationcontext.xml. First, look at what jar packages are needed to configure spring.
Here's a detailed look at the role of each jar package:
1. The jar package that AOP relies on:Aspectjweaver.jar;aspectjrt.jar
2, what is the principle of AOP to achieve it? Dynamic proxy, which is dependent on the jar package:Cglib-nodep-2.1_3.jar
3, there are also logs:Commons-logging.jar
4, finally there is the core package:Spring.jar
The following is a configuration file, Applicationcontext.xml.
<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "Http://www.springframework.org/schema/beans" xmlns: Xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:context= "Http://www.springframework.org/schema/context" xmlns:tx= "Http://www.springframework.org/schema/tx" xsi:schemalocation= "http://www.springframework.org/schema/ Beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsdhttp://www.springframework.org/schema/ Context http://www.springframework.org/schema/context/spring-context-2.5.xsdhttp://www.springframework.org/ Schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd ">//automatic scanning and assembly bean <context: Component-scan base-package= "Cn.itcast.oa" ></context:component-scan>//Import external properties file <context: Property-placeholder location= "classpath:jdbc.properties"/>//configuration Sessionfactory<bean id= "Sessionfactory" class= "Org.springframework.orm.hibernate3.LocalSessionFactoryBean" >//specify Hibernate's profile location <property name= " Configlocation "Value=" ClasspatH:hibernate.cfg.xml "></property>//configuration c3p0 database connection pool <property name=" DataSource "><bean class=" Com.mchange.v2.c3p0.ComboPooledDataSource ">//data connection information <property name= jdbcurl" value= "${jdbcurl" ></ Property><property name= "Driverclass" value= "${driverclass}" ></property><property name= "user" Value= "${user}" ></property><property name= "password" value= "${password}" ></property>//Other configurations/ /Initialize to get three connections, the value should be between Minpoolsize and Maxpoolsize. Default:3<property name= "Initialpoolsize" value= "3" ></property>//the minimum number of connections kept in the connection pool. Default:3 <property name= "Minpoolsize" value= "3" ></property>//the maximum number of connections that are kept in the connection pool. Default:15<property name= "Maxpoolsize" value= "5" ></property>//when the connection in the connection pool is exhausted c3p0 the number of connections that are fetched at the same time. Default:3 <property name= "Acquireincrement" value= "3" ></property>//control the number of preparedstatements loaded within the data source. If both maxstatements and maxstatementsperconnection are 0, the cache is closed. default:0 <property name= "maxstatements" value= "8" ></property>//maxstatementsperconnection defines the maximum number of cache statements that a single connection in a connection pool has. default:0 <property name= "Maxstatementsperconnection" value= "5" ></property>//maximum idle time, unused in 1800 seconds, the connection is discarded. If 0, it will never be discarded. default:0 <property name= "maxidletime" value= "1800" ></property></bean></property></ bean>//Configuring declarative Transaction management (in annotated manner) <bean id= "Txmanager" class= " Org.springframework.orm.hibernate3.HibernateTransactionManager "><property name=" sessionfactory "ref=" Sessionfactory "></property></bean><tx:annotation-driven transaction-manager=" TxManager "/> </beans>
Because some of the information inside the configuration file can be directly taken over, so we understand the meaning of these configuration files, when the time to use the right to take over it. The first three documents we will be the framework of the SSH three frameworks are described separately, the next blog we will explain the integration of SSH, please look forward to it!
Spring of "SSH"