You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Timothy Orme <to...@genome.med.harvard.edu> on 2009/04/06 20:34:08 UTC

Struts 2/Spring and @Required

Hello All,

	One of the nice annotation features of spring is the ability to annotate injected fields with @Required so that you don't get null pointer exceptions. However, I can only seem to get this to work 
with my test cases (spring throws an error when a required field isn't set), but I can't get the same behavior on the startup of my struts 2 web app. Does anyone know if it's possible for the web-app 
to break when an @Required field isn't set at startup?

Thanks,
Tim

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


Re: Struts 2/Spring and @Required

Posted by Timothy Orme <to...@genome.med.harvard.edu>.
Perfect, Ill give that a shot and let you know if I'm still stumped.

Thanks!
Tim

Jeroen De Ridder wrote:
> Don't forget that you need to instantiate a bean postprocessor in your 
> applicationContext to enforce the @Required-annotation:
> 
> <bean 
> class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor" 
> />
>> I don't supply any configuration to spring. I simply have the 
>> applicationContexts constructing beans, and then have a couple of 
>> lines in my struts.xml configuring the Object Factory and the autowire 
>> method.
>>
>>     <constant name="struts.objectFactory" 
>> value="org.apache.struts2.spring.StrutsSpringObjectFactory" />
>>     <constant name="struts.objectFactory.spring.autoWire" value="type" />
>>
>> and of course have the listeners set up in my web-xml. What sort of 
>> configuration would be needed to get this to work?
>>
>> Thanks,
>> Tim
>>
>> Musachy Barroso wrote:
>>> You should post your spring xml config file, it looks like some AOP
>>> config is probably missing.
>>>
>>> musachy
>>>
>>> On Mon, Apr 6, 2009 at 2:34 PM, Timothy Orme
>>> <to...@genome.med.harvard.edu> wrote:
>>>> Hello All,
>>>>
>>>>        One of the nice annotation features of spring is the ability to
>>>> annotate injected fields with @Required so that you don't get null 
>>>> pointer
>>>> exceptions. However, I can only seem to get this to work with my 
>>>> test cases
>>>> (spring throws an error when a required field isn't set), but I 
>>>> can't get
>>>> the same behavior on the startup of my struts 2 web app. Does anyone 
>>>> know if
>>>> it's possible for the web-app to break when an @Required field isn't 
>>>> set at
>>>> startup?
>>>>
>>>> Thanks,
>>>> Tim
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>
>>>>
>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 

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


Re: Struts 2/Spring and @Required

Posted by Jeroen De Ridder <vo...@gmail.com>.
Don't forget that you need to instantiate a bean postprocessor in your 
applicationContext to enforce the @Required-annotation:

<bean 
class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor" 
/>
> I don't supply any configuration to spring. I simply have the 
> applicationContexts constructing beans, and then have a couple of 
> lines in my struts.xml configuring the Object Factory and the autowire 
> method.
>
>     <constant name="struts.objectFactory" 
> value="org.apache.struts2.spring.StrutsSpringObjectFactory" />
>     <constant name="struts.objectFactory.spring.autoWire" value="type" />
>
> and of course have the listeners set up in my web-xml. What sort of 
> configuration would be needed to get this to work?
>
> Thanks,
> Tim
>
> Musachy Barroso wrote:
>> You should post your spring xml config file, it looks like some AOP
>> config is probably missing.
>>
>> musachy
>>
>> On Mon, Apr 6, 2009 at 2:34 PM, Timothy Orme
>> <to...@genome.med.harvard.edu> wrote:
>>> Hello All,
>>>
>>>        One of the nice annotation features of spring is the ability to
>>> annotate injected fields with @Required so that you don't get null 
>>> pointer
>>> exceptions. However, I can only seem to get this to work with my 
>>> test cases
>>> (spring throws an error when a required field isn't set), but I 
>>> can't get
>>> the same behavior on the startup of my struts 2 web app. Does anyone 
>>> know if
>>> it's possible for the web-app to break when an @Required field isn't 
>>> set at
>>> startup?
>>>
>>> Thanks,
>>> Tim
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>


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


Re: Struts 2/Spring and @Required

Posted by Timothy Orme <to...@genome.med.harvard.edu>.
I don't supply any configuration to spring. I simply have the applicationContexts constructing beans, and then have a couple of lines in my struts.xml configuring the Object Factory and the autowire 
method.

	<constant name="struts.objectFactory" value="org.apache.struts2.spring.StrutsSpringObjectFactory" />
	<constant name="struts.objectFactory.spring.autoWire" value="type" />

and of course have the listeners set up in my web-xml. What sort of configuration would be needed to get this to work?

Thanks,
Tim

Musachy Barroso wrote:
> You should post your spring xml config file, it looks like some AOP
> config is probably missing.
> 
> musachy
> 
> On Mon, Apr 6, 2009 at 2:34 PM, Timothy Orme
> <to...@genome.med.harvard.edu> wrote:
>> Hello All,
>>
>>        One of the nice annotation features of spring is the ability to
>> annotate injected fields with @Required so that you don't get null pointer
>> exceptions. However, I can only seem to get this to work with my test cases
>> (spring throws an error when a required field isn't set), but I can't get
>> the same behavior on the startup of my struts 2 web app. Does anyone know if
>> it's possible for the web-app to break when an @Required field isn't set at
>> startup?
>>
>> Thanks,
>> Tim
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 
> 
> 

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


Re: Struts 2/Spring and @Required

Posted by Musachy Barroso <mu...@gmail.com>.
You should post your spring xml config file, it looks like some AOP
config is probably missing.

musachy

On Mon, Apr 6, 2009 at 2:34 PM, Timothy Orme
<to...@genome.med.harvard.edu> wrote:
> Hello All,
>
>        One of the nice annotation features of spring is the ability to
> annotate injected fields with @Required so that you don't get null pointer
> exceptions. However, I can only seem to get this to work with my test cases
> (spring throws an error when a required field isn't set), but I can't get
> the same behavior on the startup of my struts 2 web app. Does anyone know if
> it's possible for the web-app to break when an @Required field isn't set at
> startup?
>
> Thanks,
> Tim
>
> ---------------------------------------------------------------------
> 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


RE: Struts 2/Spring and @Required

Posted by Martin Gainty <mg...@hotmail.com>.
//the struts-convention-plugin allows you to supply your own params e.g.

public class HelloWorld extends ActionSupport {
  @Action(value="/different/url", 
    results={@Result(name="success", type="httpheader", params={"status", "500", "errorMessage", "Internal Error"})}
http://cwiki.apache.org/WW/convention-plugin.html

does this help?
Martin 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung / Note de déni et de confidentialité 
Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.






> Date: Mon, 6 Apr 2009 14:34:08 -0400
> From: torme@genome.med.harvard.edu
> To: user@struts.apache.org
> Subject: Struts 2/Spring and @Required
> 
> Hello All,
> 
> 	One of the nice annotation features of spring is the ability to annotate injected fields with @Required so that you don't get null pointer exceptions. However, I can only seem to get this to work 
> with my test cases (spring throws an error when a required field isn't set), but I can't get the same behavior on the startup of my struts 2 web app. Does anyone know if it's possible for the web-app 
> to break when an @Required field isn't set at startup?
> 
> Thanks,
> Tim
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 

_________________________________________________________________
Rediscover Hotmail®: Get e-mail storage that grows with you. 
http://windowslive.com/RediscoverHotmail?ocid=TXT_TAGLM_WL_HM_Rediscover_Storage1_042009