MyEclipse building SSH (struts2+spring2+hibernate3) Framework Project Tutorial

Source: Internet
Author: User

After a general understanding of struts, spring, and Hibernate, it is the integration of the several frameworks. How to integrate, see below:

First: Struts2 jar and XML configuration file:

Jar Package:

Commons-fileupload-1.2.1.jar: File Upload

Commons-io-1.3.2.jar: File Reading Tool class

Freemarker-2.3.15.jar: Template engine, a generic tool for generating text output based on templates.

Ognl-2.7.3.jar: Powerful expression language instead of El Expression for data binding and display

STRUTS2-CORE-2.1.8.1.JAR:STRUTS2 Core Pack

Xwork-core-2.1.6.jar:xwork Core package is the underlying core of STRUTS2


XML files are: Web. config (struts2 core filter)

Struts.xml (Configure resource access)


Second: Spring's jar and XML configuration file

Jar Package:

Spring.jar: Contains a single jar package with a full publishing module. But not including Mock.jar, Aspects.jar, Spring-portlet.jar, and Spring-hibernate2.jar

Commons-logging: for log processing

ASPECTJRT: A jar that supports AOP

Cglib-nodep-2.1_3: Matching jars that support AOP

ASPECTJWEAVER.JSR and Aspectjrt.jar:springAOP need the package


The XML files are: Applicationcontext.xml


Third: Hibernate jar and XML configuration file

Jar Package:

Hibernate3.jar:Hibernate's core library

Antlr-2.7.6.jar: Execute support package for HQL statement

Cglib-asm.jar:cglib Library, Hibernate uses it to realize the dynamic generation of PO bytecode

XML API for Dom4j.jar:dom4j:Java

One of the Commons-collections.jar:apache Commons packages contains some Apache-developed collection classes that are more powerful than java.util.*

One of the Commons-logging.jar:apache Commons packages that contains the log function

C3p0.jar:C3PO is a database connection pool that hibernate can configure to use the C3PO connection pool.

Jta.jar:JTA specification, when Hibernate uses the JTA need

Mysql-connector-java-5.1.5-bin.jar: Link MySQL must have a package


The XML files are: Hibernate.cfg.xml: The configuration for each entity persistence, the database connection user name password, and so on.

Xx.hbm.xml: Each entity corresponds to a


IV: XML configuration and associated jar packages when spring and Struts2, Spring, and Hibernate are consolidated

Jar Package:
The Jar:struts2-spring-plugin-2.1.8.1.jar of Struts2 and spring integration is an integrated plug-in for Strus2 and spring.

Spring and hibernate do not require additional jar packages when integrated


XML configuration:

1) Web. XML configuration

<?xml version= "1.0" encoding= "UTF-8"?> <web-app version= "2.5" xmlns= "Http://java.sun.com/xml/ns/javaee"       Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee Http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd "> <!--Configure spring's listener for initializing container objects--<listener&gt        ; <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </      listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>  /web-inf/classes/applicationcontext*.xml </param-value></context-param><!--~~~~~~~~~~~struts2 Configuration          start~~~~~~~~~~~-<filter> <filter-name>struts2</filter-name> <filter-class>    Org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class> </filter>      <filter-mapping><filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!--~~~~~~~~~~~struts2 configuration end~~~~~~~~~~~-<welcome-file-list> <welcome-file>index.jsp</   Welcome-file> </welcome-file-list> </web-app>


2): Struts.xml configuration of Struts

<?xml version= "1.0" encoding= "UTF-8"?> <!  DOCTYPE struts Public "-//apache software foundation//dtd struts Configuration 2.1//en" "http://struts.apache.org/dtds/ Struts-2.1.dtd ">  <struts>  <!--set to development mode--><constant name=" Struts.devmode "value=" true "/ ><!--extension is configured as action--><constant name= "Struts.action.extension" value= "action"/>   <!--topic, Set the value to simple, that is, the UI template is not used. This will not generate additional HTML tags--><constant name= "struts.ui.theme" value= "simple"/> </struts>   

3) Spring's applicationcontext.xml 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" 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 "> <!--Import External properties file--<conte Xt:property-placeholder location= "Classpath:jdbc.properties"/> <!--configuration Sessionfactory--><bean id= "Sessionfactory" class= "Org.springframework.orm.hibernate3.LocalSessionFactoryBean" ><!-- Specify the location of the hibernate configuration file--><property name= "configlocation" value= "Classpath:hibernate.cfg.xml" ></property ><! --Connection Pool--><property name= "DataSource" ><bean class= "Com.mchange.v2.c3p0.ComboPooledDataSource" > <! --mysql Database Driver-<property name= "Driverclass" value= "${driverclass}" ></property> <!-- MySQL database name--<property name= "Jdbcurl" value= "${jdbcurl}" ></property> < login user name for!--database --<property name= "user" value= "${user}" ></property> <!--Database login password--&L T;property name= "Password" value= "${password}" ></property> <!--dialect: provides adapters for each database for easy conversion---<!-- <property name= "Hibernate.dialect" >org.hibernate.dialect.MySQLDialect</property> <!--other configurations -<!--get three connections when initializing, the value should be between Minpoolsize and Maxpoolsize. Default:3--><property name= "Initialpoolsize" value= "3" ></property><!--the minimum number of connections that are kept in the connection pool. Default:3--><property name= "Minpoolsize" value= "3" ></property><!--the maximum number of connections left 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 fetched at the same time. Default:3--><property name= "Acquireincrement" value= "3" ></property><!-- Controls 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, If not used within 1800 seconds, the connection is discarded. If 0, it will never be discarded. default:0--><property name= "maxidletime" value= "1800" ></property></bean></property>   </bean> </beans>


4) Hibernate's hibernate.cfg.xml configuration and Xx.hbm.xml configuration

Hibernate.cfg.xml

<! DOCTYPE hibernate-configuration public      "-//hibernate/hibernate configuration DTD 3.0//en"      "http// Hibernate.sourceforge.net/hibernate-configuration-3.0.dtd ">    
xx.hbm.xml configuration, it goes without saying.


Summarize:

In this way, the SSH framework is integrated, which is the best way to understand the design and thinking of the framework. The SSH framework is well integrated, and it is checked by an example. See the next blog post.




MyEclipse building SSH (struts2+spring2+hibernate3) Framework Project Tutorial

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.