Struts and Spring together?

I am new to both Struts and Spring. I need to know how to access the Spring service in a Struts ActionForm. Even a pointer in the right direction would be appreciated.

+2
source share
3 answers

From the struts 1 ActionForm class, you'll need:

WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext).getBean("yourService");
+2
source

Do you use Struts 1 or 2?

If you are using Struts 1, there are several ways to do this. I prefer to do this using org.springframework.web.struts.DelegatingActionProxy. You will need spring -webmvc-struts.jar in the classpath.

spacers-config.xml:

   <action path="/faq" type="org.springframework.web.struts.DelegatingActionProxy" name="faqForm" parameter="method">
        <forward name="List" path="faq.list" />
    </action>

applicationContext.xml:

<bean name="/faq" class="com.mypackage.FAQAction" autowire="byType" />

, , spring.

, , 1 spring. developerWorks developerWorks, , google " Struts Spring" (, , ).

+2

spring -xml.

<listener>
 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<constant name="struts.objectFactory" value="spring"/>

struts.xml.

, :

class MyAction {
  @Autowired MyService service;
   ....
}

, struts2.

+1

Source: https://habr.com/ru/post/1722253/


All Articles