Go How Struts2 is handing action to spring hosting

Source: Internet
Author: User
Tags hosting

Example 1:

First, take a look at how to get spring to manage the action.


1. Add <constant name= "struts.objectfactory" value= "Spring"/> in Struts.xml
There are two ways to integrate:
(1) The business logic controller class of struts is configured in the spring configuration file, and the business class referenced in the action is injected together.

(This process requires that the scope of the action class be configured as prototype)

XML Code
  1. < bean  id= "loginaction " class=" Yaso.struts.action.LoginAction ">  
  2. <property name=ref=" Logindao " span class= "tag" style= "Color: #006699; Font-weight:bold; " >/>  
  3. </Bean>

Then, when you configure the action in the Struts.xml or equivalent Struts2 configuration file, the class property of the specified <action> is the ID or name value of the corresponding bean in the spring configuration file. Examples are as follows:

XML Code
  1. < action name= "Loginaction"  class= "loginaction" >  
  2.                       <result name= "Success" >/index.jsp</result>  
  3. </Action>

(2) The business class is configured in the spring configuration file, the action does not need to be configured, and the STRUTS2 action is configured as before the spring is integrated

The class attribute of <action> specifies the fully qualified name of the business logic controller class. The business class referenced in the action does not need to be initialized by itself,

STRUTS2 's spring plug-in uses the bean's automatic assembly to inject the business class, but the action is not Struts2 created,

Instead, STRUTS2 's spring plugin was created. By default, plugins are assembled by using the By name method,

You can modify the matching method by adding Struts2 constants: Set mode

is: Struts.objectFactory.spring.autoWire = TypeName,

The optional assembly parameters are as follows:

Name: autowrie= "byname" equivalent to spring configuration (default)
Type: autowrie= "Bytype" equivalent to spring configuration
Auto: autowrie= "AutoDetect" equivalent to spring configuration
Constructor: Autowrie= "constructor" equivalent to spring configuration

Example 2:how action in Java struts2 is managed by spring
Struts2.xml add <constant name= "struts.objectfactory" value= "Spring" ></constant>
Add Struts2-spring-plugin jar Package, change the class of the action configuration to spring's bean ID value
inquiry:
Is that what you have to add? <constant name= "Struts.objectfactory" value= "Spring" ></constant>
I don't think it's the same thing as integration.
Chase Answer:
It can be used without struts2-spring-plugin, and struts will recognize it automatically when it has a



Example 3:
Give struts2 action to spring to manage and inject attributes, struts.xml how to write 
Added: Struts2-spring-plugin.jar
Add a sentence in the struts2 XML file:
<constant name= "Struts2. Objectfactory "value=" Spring "/> This sentence
If your struts2 version is relatively high, you can also do not add this, because he has been added by default inside this sentence
Then <action name= "" class= "..."/> The Name property is the ID of the bean referencing the spring configuration

Everything else is written as before.

Go How Struts2 is handing action to spring hosting

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.