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
- < bean id= "loginaction " class=" Yaso.struts.action.LoginAction ">
- <property name=ref=" Logindao " span class= "tag" style= "Color: #006699; Font-weight:bold; " >/>
- </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
- < action name= "Loginaction" class= "loginaction" >
- <result name= "Success" >/index.jsp</result>
- </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