struts-2.3+spring-4.0+hibernate-4.0 Integration Project

Source: Internet
Author: User

1. Join Spring
1) Add Jar Package
2) Configure Web. XML applicationcontext.xml (Listener)
3) Add Spring Config file: AOP context TX Bean

1. Join Hibernate
1.1 Establish a persistence class, and its corresponding xxx,hbm. XML file, production of the corresponding data table
1.2spring Integrated Hibernate

1) Add Jar Package
2) Add the Hibernate.cfg.xml file under Class path. Where hibernate is configured for basic configuration
3) Establish persistence classes and corresponding XXX.HBM. Xml
4) and Spring integration
A) Add c3p0 and MySQL drivers
b) Configure in spring configuration file: Data source, Sessionfactory, declarative transaction

5) Start the project, you will see the production of the corresponding data sheet

3. Join STRUTS2
1) Add jar package, have duplicate package, delete package with low version
2) on the web. Configure the STRUTS2 filter in the XML file
3) Add config file Struts.xml
4) Integrate Spring
A) Add the jar package for the spring plugin of Struts2
b) properly configure the action in spring's configuration file and set scope to prototype
c) When action is in Struts2 's configuration file, the class attribute points to the ID of the action in the IOC

Note: The first line of the following code only acts as a marker comment, please remove it when developing!

<!--web .<?xml version= "1.0" encoding= "UTF-8"? ><web-app xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns= "Http://java.sun.com/xml/ns/javaee" xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee/http Java.sun.com/xml/ns/javaee/web-app_3_0.xsd "id=" webapp_id "version=" 3.0 "><!--Configure Spring Listener-->< Context-param><param-name>contextconfiglocation</param-name><param-value>classpath: Applicationcontext*.xml</param-value></context-param><listener><listener-class> org.springframework.web.context.contextloaderlistener</listener-class></listener><!-- Configuring the Struts2 filter--><filter> <filter-name>struts2</filter-name> <filter-class>or G.apache.struts2.dispatcher.ng.filter.strutsprepareandexecutefilter</filter-class> </filter> <    Filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mApping> </web-app> 

  

<!--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:aop= "Http://www.springframework.org/schema/aop" 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.XSDHTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/ Spring-aop-3.2.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/ Spring-context-3.2.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/ Spring-tx-3.2.xsd "> <!--Import resource file--<context:property-placeholder location=" Classpath:db.properties "    /> <!--configuring C3P0 data Source-<bean id= "DataSource" class= "Com.mchange.v2.c3p0.ComboPooledDataSource" > <propErty name= "user" value= "${jdbc.user}" ></property> <property name= "password" value= "${jdbc.password}" ></property> <property name= "Driverclass" value= "${jdbc.driverclass}" ></property> < Property Name= "Jdbcurl" value= "${jdbc.jdbcurl}" ></property> <property name= "initialpoolsize" value= "${ Jdbc.initpoolsize} "></property> <property name=" maxpoolsize "value=" ${jdbc.maxpoolsize} "></ Property> </bean> <!--configuration Sessionfactory--<bean id= "sessionfactory" class= "ORG.SPRINGFR Amework.orm.hibernate4.LocalSessionFactoryBean "> <property name=" dataSource "ref=" DataSource "></ property> <property name= "configlocation" value= "Classpath:hibernate.cfg.xml" ></property> <        Property Name= "Mappinglocations" value= "Classpath:xby/ssh/entities/*.hbm.xml" ></property> </bean> <!--Configure Spring declarative transactions--<!--1. Configure Hibernate transaction Manager-&LT;bean id= "TransactionManager" class= "Org.springframework.orm.hibernate4.HibernateTransactionManager" > < Property Name= "Sessionfactory" ref= "sessionfactory" ></property> </bean> <!--2. Configure transaction Properties--&L T;tx:advice id= "Txadvice" transaction-manager= "TransactionManager" > <tx:attributes> <tx:method name= "ge t* "read-only=" true "/> <tx:method name=" * "/> </tx:attributes> </tx:advice> <!--3. Configuring transactions Pointcut--then associate transaction properties with transaction Pointcuts-<aop:config> <aop:pointcut expression= "Execution (* xby.ssh.service.*.* (.       ) "id=" Txpointcut "/> <aop:advisor advice-ref=" Txadvice "pointcut-ref=" Txpointcut "/> </aop:config> </beans>

  

<!--applicationcontext-beans.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 "xsi: schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans.xsd "><bean id=" EmployeeDAO "class=" Xby.ssh.dao.EmployeeDao "><property name=" Sessionfactory "ref=" sessionfactory "></property></bean><bean id=" EmployeeService "class=" Xby.ssh.service.EmployeeService "><property name=" EmployeeDAO "ref=" EmployeeDAO "></property></ Bean><bean id= "employeeaction" class= "Xby.ssh.actions.EmployeeAction" scope= "prototype" ><property name = "EmployeeService" ref= "EmployeeService" ></property></bean></beans>

  

<!--struts.xml--<?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE struts public    "-//apache software foundation//dtd struts Configuration 2.0//en"    "/http Struts.apache.org/dtds/struts-2.0.dtd ><struts>    <!--This property sets whether Struts2 supports dynamic method calls, and the default value for this property is true--    <constant name= "Struts.enable.DynamicMethodInvocation" value= "false"/> <constant    name= " Struts.devmode "value=" true "/>    <package name=" Default "namespace="/"extends=" Struts-default ">        <action name= "emp-*" class= "employeeaction"          method= "{1}" >         <result name= "list" >/web-inf/views/ emp-list.jsp</result>         </action>    </package></struts>

  

<!--hibernate.cfg.xml--  <?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE hibernate-configuration Public "-//hibernate/hibernate configuration DTD 3.0//en" "http// Hibernate.sourceforge.net/hibernate-configuration-3.0.dtd ">
Db.propertitesjdbc.user=rootjdbc.password=rootjdbc.driverclass=com.mysql.jdbc.driverjdbc.jdbcurl=jdbc:mysql ://localhost:3306/sshjdbc.initpoolsize=5jdbc.maxpoolsize=10

  

The above is all the jar packages, the full version, tested without problems. If you need one, you can have a private person.

struts-2.3+spring-4.0+hibernate-4.0 Integration Project

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.