Struts2 spring Configuration

Source: Internet
Author: User

[Html]
(1) Configure struts2 in eclipse
 
(2) copy the struts2-spring-plugin-2.0.11.2.jar package to the WEB-INF \ lib directory
(3) Configure spring in web. xml
<Listener>
<Listener-class> org. springframework. web. context. ContextLoaderListener </listener-class>
</Listener>
Remember, if you have used spring before, please remove the spring configuration.
<Servlet>
<Servlet-name> context </servlet-name>
<Servlet-class>
Org. springframework. web. context. ContextLoaderServlet
</Servlet-class>
<Load-on-startup> 1 </load-on-startup>
</Servlet>
(4) Modify applicationContext. xml
<Beans default-autowire = "byName" 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-2.0.xsd">
(5) add in struts. xml
<Constant name = "struts. objectFactory" value = "spring"/>
(6) define action in the spring configuration file applicationContext. xml
<Bean id = "SearchBusLineAction"
Class = "com. bus. struts2.action. SearchBusLineAction" abstract = "false"
Lazy-init = "default" autowire = "default" dependency-check = "default">
<Property name = "busService">
<Ref bean = "BusServiceImpl"/>
</Property>
</Bean>
(7) define action in struts. xml
<! -- Note that class = "SearchBusLineAction" instead of com. bus. struts2.action. SearchBusLineAction is defined in applicationContext. xml of spring. -->
<Action name = "searchBusLine" class = "SearchBusLineAction">
<Result name = "success" type = "freemarker">/index. jsp </result>
</Action>
(1) Configure struts2 in eclipse

(2) copy the struts2-spring-plugin-2.0.11.2.jar package to the WEB-INF \ lib directory
(3) Configure spring in web. xml
<Listener>
<Listener-class> org. springframework. web. context. ContextLoaderListener </listener-class>
</Listener>
Remember, if you have used spring before, please remove the spring configuration.
<Servlet>
<Servlet-name> context </servlet-name>
<Servlet-class>
Org. springframework. web. context. ContextLoaderServlet
</Servlet-class>
<Load-on-startup> 1 </load-on-startup>
</Servlet>
(4) Modify applicationContext. xml
<Beans default-autowire = "byName" 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-2.0.xsd">
(5) add in struts. xml
<Constant name = "struts. objectFactory" value = "spring"/>
(6) define action in the spring configuration file applicationContext. xml
<Bean id = "SearchBusLineAction"
Class = "com. bus. struts2.action. SearchBusLineAction" abstract = "false"
Lazy-init = "default" autowire = "default" dependency-check = "default">
<Property name = "busService">
<Ref bean = "BusServiceImpl"/>
</Property>
</Bean>
(7) define action in struts. xml
<! -- Note that class = "SearchBusLineAction" instead of com. bus. struts2.action. SearchBusLineAction is defined in applicationContext. xml of spring. -->
<Action name = "searchBusLine" class = "SearchBusLineAction">
<Result name = "success" type = "freemarker">/index. jsp </result>
</Action>

Author: Tender001
 

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.