struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Antonius Ng <anton...@gmail.com>
Subject Re: Rest-plugin with Spring
Date Tue, 20 Oct 2009 00:55:04 GMT
Hi Sayantan,

Sure I can share it. I am not sure I am doing it the right way or not, but
here it is.

I created a new class that extends StrutsSpringObjectFactory:

public class RestSpringObjectFactory extends StrutsSpringObjectFactory {
...

Then I override the following method
public Object buildBean(Class clazz, Map<String, Object> extraContext)
throws Exception {
...
//Depending on how you name the bean in Spring applicationContext. If you
name the bean with the classname of the controller, you can do the following
String beanId = clazz.getName();

//Getting bean from Spring
o = appContext.getBean(    beanId     );
...
return o;
...

}

For details, you can refer to the code StrutsSpringObjectFactory. It is very
straightforward. Although I think there maybe a better way to achieve this.

For applicationContext.xml, there is really nothing special. It's just a
normal bean definition:
<bean id=...  class=.... scope="prototype"/>


Cheers,
Antonius

On Mon, Oct 19, 2009 at 12:25 PM, Sayantan Sinha <sayantan.sinha@tcs.com>wrote:

>
> Hi Antonius,
>
> Thanks for your promp reply. Can you please share the code for the class
> RestSpringObjectFactory? Also, it would be great if you can share your
> applicationContext.xml (spring configuration) file.
>
> Also, please confirm is the spring injection working properly.
>
> Regards,
> Sayantan
>
>
> Antonius Ng-2 wrote:
> >
> > Hi Sayantan,
> >
> > This is how I do it. In struts.xml, I add the following line:
> > <constant name="struts.objectFactory"
> > value="com.sippku.rest.spring.RestSpringObjectFactory" />
> >
> > Cheers,
> > Antonius
> >
> >
> > On Sun, Oct 18, 2009 at 4:42 PM, Sayantan Sinha
> > <sayantan.sinha@tcs.com>wrote:
> >
> >>
> >> Hi,
> >>
> >> How do you make your application read this new class
> >> RestSpringObjectFactory?
> >> Thanks in advance.
> >>
> >> Regards,
> >> Sayantan
> >>
> >>
> >> Antonius Ng-2 wrote:
> >> >
> >> > Hi again,
> >> >
> >> > I solve this problem by writing a new class: RestSpringObjectFactory
> >> which
> >> > extends StrutsSpringObjectFactory. In that class, i override the
> method
> >> > buildBean(Class clazz, Map<String, Object> extraContext)  to get
bean
> >> from
> >> > appContext whenever the class is my controller class.
> >> >
> >> > Cheers,
> >> > Anton
> >> >
> >> > On Sat, Sep 19, 2009 at 5:11 PM, Antonius Ng <antonius@gmail.com>
> >> wrote:
> >> >
> >> >> Hi all,
> >> >>
> >> >> I am currently developing an application using Struts 2.1.6 +
> >> rest-plugin
> >> >> +
> >> >> spring-plugin + Spring 2.5.6.
> >> >>
> >> >> The problem that I am facing is that I have not found any way to
> >> >> initialize
> >> >> the Controller Actions from Spring, because the rest-plugin is built
> >> on
> >> >> the
> >> >> Convention Plugin for automatic configuration of actions.
> >> >>
> >> >> I have a Controller called com.x.y.z.controller.OrdersController.
> >> >>
> >> >> The following is my struts.xml
> >> >> <struts>
> >> >>     <constant name="struts.objectFactory" value="spring" />
> >> >>     <constant name="struts.devMode" value="false" />
> >> >>
> >> >>     <!--  Overwrite Convention -->
> >> >>     <constant name="struts.mapper.idParameterName"
> >> value="uniqueName"/>
> >> >>     <constant name="struts.convention.action.suffix"
> >> value="Controller"/>
> >> >>     <constant name="struts.convention.action.mapAllMatches"
> >> >> value="true"/>
> >> >>     <constant name="struts.convention.default.parent.package"
> >> >> value="rest-default"/>
> >> >>     <constant name="struts.convention.package.locators"
> >> >> value="controller"/>
> >> >>     <constant name="struts.convention.package.locators.basePackage"
> >> >> value="com.x.y.z"/>
> >> >>  </struts>
> >> >>
> >> >> Is there anyway that I can initialize this Controller from Spring?
Or
> >> >> perhaps there is anything that I can add to my struts.xml file?
> >> >>
> >> >> Thanks in advance,
> >> >> Anton
> >> >>
> >> >
> >> >
> >>
> >> --
> >> View this message in context:
> >> http://www.nabble.com/Rest-plugin-with-Spring-tp25520270p25945240.html
> >> Sent from the Struts - User mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> For additional commands, e-mail: user-help@struts.apache.org
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Rest-plugin-with-Spring-tp25520270p25953488.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message