|
This post originated from an RSS feed registered with Java Buzz
by Marc Logemann.
|
Original Post: XDoclet Spring+Struts HowTo
Feed Title: Marc's Java Blog
Feed URL: http://www.logemann.org/day/index_java.xml
Feed Description: Java related topics for all major areas. So you will see J2ME, J2SE and J2EE issues here.
|
Latest Java Buzz Posts
Latest Java Buzz Posts by Marc Logemann
Latest Posts From Marc's Java Blog
|
|
For all those out there using Spring together with Struts, i created a small howTo regarding automatic generation of relevant files, especially the boring action-servlet-xml file which must be in synch with your struts-config.xml, at least for all Struts actions which should be injected by Spring.
Lets start with the Action class:
/**
* Action to delete a Client
* Date: 09.02.2005
* Time: 15:29:15
*
* @author Logemann - Logentis e.K.
* @version $Id$
* @struts.action path="clientDelete" validate="false"
* type="org.springframework.web.struts.DelegatingActionProxy"
* name="emptyform"
* @struts.action-forward name="back"
* path="/clientManager.html" redirect="true"
* @spring.bean name="clientDelete"
*/
public class ClientDeleteAction extends Action {
ClientManager clientManagerService;
/**
* Spring injection
*
* @param clientManagerService clientManagerService
* @spring.property ref="clientManagerService"
*/
public void setClientManagerService(ClientManager clientManagerService) {
this.clientManagerService = clientManagerService;
}
[..]
|
With this tags, the ant build target outlined below will create a struts-config.xml and the necessary action-servlet.xml needed by Spring. Lets see how the target looks:
|
classname="xdoclet.modules.spring.SpringDocletTask"
classpathref="classpath"/>
classname="xdoclet.modules.web.WebDocletTask"
classpathref="classpath"/>
|
Be sure to modify the classpath definition and the destDir values of springdoclet and webdoclet to suit your needs. Right now the Spring task only searches for Actions in order to create action-servlet.xml, if you also want to create your normal service beans like ClientManagerService, you should create another springdoclet task and output things to applicationContext.xml if you like.
But this is mostly users choice, as you know, Spring supports from one to many bean definition files and its up to you how you want to have your spring xml world.
This will be created when you run the mentioned target:
(action-servlet.xml)
"-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd"> |
default-autowire="no"
default-lazy-init="false"
default-dependency-check="none"
>
name="clientDelete"
class="de.logentis.versysng.action.clientmanager.ClientDeleteAction"
>