File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Struts2-Spring annotation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2-Spring annotation" Watch "Struts2-Spring annotation" New topic
Author

Struts2-Spring annotation

Paul Michael Serrano
Ranch Hand

Joined: Nov 22, 2004
Posts: 59
I do have a question regarding annotation for Struts2-Spring plugin. I want my action classes to be annotated.
How could we map the class attribute of action element in struts.xml to id attribute of bean element in applicationContext.xml?

srtuts.xml


applicationContext.xml



If I'm going to look at the org.apache.struts2.convention.annotation.Action interface, the only properties there are

value
results
interceptorRefs
params
exceptionMappings

And what I'm planning to do is move my entries inside my struts.xml to annotations in my action classes but the thing is I could not map the class attribute of action element(struts.xml) to the id attribute of bean element (applicationContext.xml)



Do you have suggestions on how I could make my action classes annotated?

-Paul

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

If you're not using a Struts 2 XML config file there's no mapping required, because there's no Struts 2 XML to map to.
Paul Michael Serrano
Ranch Hand

Joined: Nov 22, 2004
Posts: 59
Hi Dave,

Currently we do have struts.xml in our application and it is being shared accross the application (some of the entries are not mine).
So I removed this in my struts.xml:

I tried to putting some of the entries in our struts.xml into annotations, after that our codes look like this one:

After that, we decided to put Spring into our application and downloaded the Struts2-Spring plugin. I tried to follow the documentation of for using the plugin:
http://struts.apache.org/2.x/docs/spring-plugin.html and ended up on going back to the struts.xml config.
struts.xml

and applicationContext.xml

How could I make use of the convention plugin for Struts2-Spring plugin, so that I will not make an entry for struts.xml? Do you have any site or document to look at for this topic?


Thanks,
Paul
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You already *were* using the Convention plugin, no? Which annotations were you using?

In any case, once you're using the Spring plugin, actions are instantiated through Spring, and as such, can be auto-wired, annotated, etc. like any other Spring bean.
Puneet Babbar
Greenhorn

Joined: Jul 11, 2011
Posts: 1
Hey i am facing the same trouble - have to add spring support to my struts 2 application and i have no clue, as to how will be using a bean created from the action class to be read by the struts 2 framework as the action class.
Since i am using convention plugin and i dont have a struts.xml file in my application, where will i specify this? I can do the same thing using struts.xml but haven't been able to find any way to do it without this file.

Were you able to find the approach to solve this issue?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts2-Spring annotation