You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by psavage <ps...@yahoo.com> on 2009/10/07 19:30:30 UTC

RE: TypeConverter needs Spring Bean

This definitely used to work in previous Struts versions (e.g. 2.0.7, 2.0.9,
and 2.0.14) so I think this is a bug. In fact, this bug had occurred in
previous 2.0.x versions but had been fixed (see
http://jira.opensymphony.com/browse/XW-472). I submitted an XWork bug a
couple weeks ago (http://jira.opensymphony.com/browse/XW-725), but so far
there is no response.

In previous Struts versions, the object factory used to instantiate type
converters was org.apache.struts2.spring.StrutsSpringObjectFactory, but in
2.1.6 it is com.opensymphony.xwork2.ObjectFactory instead. The
implementation of http://jira.opensymphony.com/browse/XW-566 probably caused
this because the object factory used to create type converters is now
injected instead of statically set. In the reloadContainer method of
com.opensymphony.xwork2.config.impl.DefaultConfiguration, ObjectFactory is
used to create the bootstrap container which contains XWorkConverter.
Therefore, an ObjectFactory instance gets injected into XWorkConverter which
means that the type converters in xwork-conversion.properties cannot be
Spring beans.

This seems to be a major bug. Is anyone working on a fix?


Griffith, Michael * wrote:
> 
> Thanks for the suggestion. Maybe this should be considered as a future
> feature enhancement.
> 
> MG
> 
> -----Original Message-----
> From: Musachy Barroso [mailto:musachy@gmail.com] 
> Sent: Friday, February 06, 2009 9:12 AM
> To: Struts Users Mailing List
> Subject: Re: TypeConverter needs Spring Bean
> 
> The converters are created by the internal IOC container, so the Spring
> beans wont be injected. A "hack" I can think of is to add something like
> this to the converter:
> 
> @Inject(StrutsConstants.STRUTS_OBJECTFACTORY)
> public void setObjectFactory(ObjectFactory factory) {
>    //save the factory for later
> }
> 
> that factory will be the Spring object factory, which you can use to
> lookup the beans that you need. Not much of "inversion of control" but
> it should work.
> 
> musachy
> 
> On Fri, Feb 6, 2009 at 9:59 AM, Griffith, Michael *
> <Mi...@fda.hhs.gov> wrote:
>> How can you tell? This is handed by the plug-in, right? From my 
>> struts.properties file:
>>
>> struts.objectFactory = spring
>> struts.objectFactory.spring.autoWire = name 
>> struts.objectFactory.spring.useClassCache = true
>>
>> -----Original Message-----
>> From: Musachy Barroso [mailto:musachy@gmail.com]
>> Sent: Friday, February 06, 2009 8:54 AM
>> To: Struts Users Mailing List
>> Subject: Re: TypeConverter needs Spring Bean
>>
>> Are the converters created by the object factory? if not, then it will
> 
>> not work.
>>
>> musachy
>>
>> On Fri, Feb 6, 2009 at 9:46 AM, Griffith, Michael * 
>> <Mi...@fda.hhs.gov> wrote:
>>> I also tried adding the @Autowired annotation to the dependency, but 
>>> it did not work.  Can anyone clarify how this is supposed to work?
>>> MG
>>>
>>> -----Original Message-----
>>> From: Steven Yang [mailto:kenshin520@gmail.com]
>>> Sent: Thursday, February 05, 2009 8:15 PM
>>> To: Struts Users Mailing List
>>> Subject: Re: TypeConverter needs Spring Bean
>>>
>>> Hi
>>> I also need my Converter to be handled by Spring however I could not 
>>> get it to work as well.
>>> From my observation is that the Converter is set to X-Work but not to
> 
>>> Struts, there for the Spring plugin may not work there.
>>> Please correct me if I am wrong.
>>> Or is there a correct way to set it up?
>>>
>>> Thanks
> 

-- 
View this message in context: http://www.nabble.com/TypeConverter-needs-Spring-Bean-tp21859590p25790977.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


Re: TypeConverter needs Spring Bean

Posted by Musachy Barroso <mu...@gmail.com>.
I think that one fell through the cracks.

musachy

On Wed, Oct 7, 2009 at 10:30 AM, psavage <ps...@yahoo.com> wrote:
>
> This definitely used to work in previous Struts versions (e.g. 2.0.7, 2.0.9,
> and 2.0.14) so I think this is a bug. In fact, this bug had occurred in
> previous 2.0.x versions but had been fixed (see
> http://jira.opensymphony.com/browse/XW-472). I submitted an XWork bug a
> couple weeks ago (http://jira.opensymphony.com/browse/XW-725), but so far
> there is no response.
>
> In previous Struts versions, the object factory used to instantiate type
> converters was org.apache.struts2.spring.StrutsSpringObjectFactory, but in
> 2.1.6 it is com.opensymphony.xwork2.ObjectFactory instead. The
> implementation of http://jira.opensymphony.com/browse/XW-566 probably caused
> this because the object factory used to create type converters is now
> injected instead of statically set. In the reloadContainer method of
> com.opensymphony.xwork2.config.impl.DefaultConfiguration, ObjectFactory is
> used to create the bootstrap container which contains XWorkConverter.
> Therefore, an ObjectFactory instance gets injected into XWorkConverter which
> means that the type converters in xwork-conversion.properties cannot be
> Spring beans.
>
> This seems to be a major bug. Is anyone working on a fix?
>
>
> Griffith, Michael * wrote:
>>
>> Thanks for the suggestion. Maybe this should be considered as a future
>> feature enhancement.
>>
>> MG
>>
>> -----Original Message-----
>> From: Musachy Barroso [mailto:musachy@gmail.com]
>> Sent: Friday, February 06, 2009 9:12 AM
>> To: Struts Users Mailing List
>> Subject: Re: TypeConverter needs Spring Bean
>>
>> The converters are created by the internal IOC container, so the Spring
>> beans wont be injected. A "hack" I can think of is to add something like
>> this to the converter:
>>
>> @Inject(StrutsConstants.STRUTS_OBJECTFACTORY)
>> public void setObjectFactory(ObjectFactory factory) {
>>    //save the factory for later
>> }
>>
>> that factory will be the Spring object factory, which you can use to
>> lookup the beans that you need. Not much of "inversion of control" but
>> it should work.
>>
>> musachy
>>
>> On Fri, Feb 6, 2009 at 9:59 AM, Griffith, Michael *
>> <Mi...@fda.hhs.gov> wrote:
>>> How can you tell? This is handed by the plug-in, right? From my
>>> struts.properties file:
>>>
>>> struts.objectFactory = spring
>>> struts.objectFactory.spring.autoWire = name
>>> struts.objectFactory.spring.useClassCache = true
>>>
>>> -----Original Message-----
>>> From: Musachy Barroso [mailto:musachy@gmail.com]
>>> Sent: Friday, February 06, 2009 8:54 AM
>>> To: Struts Users Mailing List
>>> Subject: Re: TypeConverter needs Spring Bean
>>>
>>> Are the converters created by the object factory? if not, then it will
>>
>>> not work.
>>>
>>> musachy
>>>
>>> On Fri, Feb 6, 2009 at 9:46 AM, Griffith, Michael *
>>> <Mi...@fda.hhs.gov> wrote:
>>>> I also tried adding the @Autowired annotation to the dependency, but
>>>> it did not work.  Can anyone clarify how this is supposed to work?
>>>> MG
>>>>
>>>> -----Original Message-----
>>>> From: Steven Yang [mailto:kenshin520@gmail.com]
>>>> Sent: Thursday, February 05, 2009 8:15 PM
>>>> To: Struts Users Mailing List
>>>> Subject: Re: TypeConverter needs Spring Bean
>>>>
>>>> Hi
>>>> I also need my Converter to be handled by Spring however I could not
>>>> get it to work as well.
>>>> From my observation is that the Converter is set to X-Work but not to
>>
>>>> Struts, there for the Spring plugin may not work there.
>>>> Please correct me if I am wrong.
>>>> Or is there a correct way to set it up?
>>>>
>>>> Thanks
>>
>
> --
> View this message in context: http://www.nabble.com/TypeConverter-needs-Spring-Bean-tp21859590p25790977.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
>
>



-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org