Struts2 + spring integration framework

Source: Internet
Author: User

Struts2 + spring integration framework
1. Copy the struts2-spring-plugin-x-x-x.jar and the corresponding spring. jar to the/WEB-INF/lib directory. Struts2-spring-plugin-x-x-x.jar in struts2 lib, x-x is version 2. in struts. set struts in properties. objectFactory attribute value struts. propertiesstruts. objectFactory = spring or configure struts as a constant in the XML file. xml <struts> <constant name = "struts. objectFactory "value =" spring "/> </struts> 3. in the web. add Spring context parameters and listeners in xml format <! -- Used to locate the context configuration of the Spring XML file --> <context-param> <param-name> contextConfigLocation </param-name> <param-value>/WEB-INF/applicationContext -*. xml, classpath *: applicationContext -*. xml </param-value> </context-param> web. xml <listener> <listener-class> org. springframework. web. context. contextLoaderListener </listener-class> </listener> 4. modify the Struts configuration file. 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> <! -- Set struts. objectFactory property value --> <constant name = "struts. objectFactory "value =" spring "/> <package name =" struts-config "namespace ="/"extends =" struts-default "> <action name =" login "class = "loginAction" <result name = "frame">/frame. jsp </result> </action> </package> </struts> applicationConext. 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: p = "http://www.springframework.org/schema/p" xsi: schemaLocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean name = "loginAction" class = "com. system. action. loginAction "scope =" prototype "> </bean> </beans> struts. in the xml file, the class attribute in <action name = "" class = ""> is changed from the class path to the custom class name applicationConext. <bean name = "Custom Class name (same as struts. the class definition in the xml file is the same.) "class =" class path "> 5. now, your Struts2 and Spring can work normally together.

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.