|
We build a Struts web application using the greeting service through Spring like using in Hello world application above
Design and Code This example is quite simple. It includes only an Action class,GreetingAction,to use Spring application context to look up the greeting service and request for service. The diagram below shows the sequential interactions between GreetingAction,Spring application context,and GreetingService
 
a Struts plug-in that is aware of the Spring application context. Add the following code to your struts-config.xml to register the plug-in:
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="/WEB-INF/spring-services.xml"/>
</plug-in>
ContextLoaderPlugIn loads a Spring application context (a WebApplication- Context,to be specific),using the context configuration files listed (comma separated)in its contextConfigLocation property.
The spring-services.xml declares only bean service with content as in following:

When receive request,GreetingAction will use Spring application context to look up GreetingService,the code below shows that:


How to run Steps below describe the ways to deploy and run this web application on Tomcat
1. Register GreetingService as a common service on Tomcat by copying greetings.jar file into $CATALINA_HOME/commons/endorsed,figure below is for example:
 
2. Deploy the web application by copying it into Tomcat web folder:

3. Open web browser and go to the link below:

|