...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<?xml version="1.0" encoding="UTF-8"?>
<beans 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.xsd">
<bean id="editService" class="org.apache.struts.edit.service.EditServiceInMemory" />
<bean id="editAction" class="org.apache.struts.edit.action.EditAction" scope="prototype">
<property name="editService" ref="editService" />
</bean>
</beans>
|
Note in the above that there is an editAction
bean bean and its editService
property property is set to the editService
bean bean. Since we are having Spring manage the EditAction
class class we must specify any properties of EditAction
that that we want Spring to inject. Please remember that actions must be created on each request, they cannot be singletons
- this is the default scope
that's why it must be changed to prototype
.
In the struts.xml
configuration configuration file you must specify the Spring id value for the class attribute of the action node. This tells Struts to get a bean with that id value from Spring for the Action class.
...