Spring + hibernate + struts2 integration solution (1)

Source: Internet
Author: User

Integration of Struts2 and Spring: 1. add jar package (note package conflict), also need to note must be added to the struts2-spring-plugin.jar package 2. add support files (struts. xml and applicationContext. xml) 3. configure web. xml (1) configure the startup parameters required for spring initialization (wildcards can be used to separate multiple files if they are available) <context-param> <param-name> contextConfigLocation </param-name> <param-value> classpath: applicationContext. xml </param-value> </context-param> (2) configure the spring context listener (mainly used to generate a WepApplicationContext object at startup) <listener> <listener-class> or G. springframework. web. context. contextLoaderListener </listener-class> </listener> (3) configure the filter of struts2. develop implementation code for each layer. 5. in applicationContext. when configuring various beans in xml, note that the configuration of action bean is the same as that of other beans. 6. in struts. configure Action in xml. For the rest, you only need to set the class value to the id of the action Bean we configured in spring. Integration of Spring and Hibernate: 1. add corresponding jar packages. 2. add corresponding support files. 3. configure the SessionFactory object of Hibernate in the spring configuration file, and use the core configuration file of Hibernate as its attribute value. You can also choose not to use the core configuration file of hibernate. All the ing information is configured in spring, but this will increase the difficulty of coding, so this method is rarely used. <! -- Configure the sessionFactory object --> <bean id = "sessionFactory" www.2cto.com class = "org. springframework. orm. hibernate3.LocalSessionFactoryBean"> <! -- Import the core configuration file of hibernate --> <property name = "configLocation" value = "classpath: hibernate. cfg. xml "> </property> </bean> 4. when writing a Data Handler class Dao, the DAO directly or indirectly inherits from HibernateDaoSupport. We can use the hibernateTemplate attribute in this class to perform various data operations, this template object will help us complete the non-technical operations. 5. configure our Dao. Note that the sessionFactory attribute needs to be configured during configuration. 6. Configure the OSIV filter to solve the problem that the session has been disabled)

Related Article

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.