Just about every single S2 action I have ever created uses Spring to inject
a service object of some sort into the action. I use Spring for
transactions, SLSB's, MDB's, JDBC, Hibernate, you name it.

Ganfab asked about injecting a new instance of an object into a custom
interceptor on every action call and my thinking was that Spring had only
constructor or setter injection and that interceptors were always
singletons, so the injected bean would always be a singleton. Well I just
found in Spring 2.5 they have lookup method injection which can be used to
create a new instance of an object from the Spring bean factory and inject
them into a Singleton. Using this you could inject new instances and declare
your interceptor in a package and not have to declare it for every action
needing this type of interceptor. See 3.3.7.1.

http://static.springframework.org/spring/docs/2.5.x/reference/beans.html#bea
ns-factory-method-injection

I hope I'm being clear about what I mean. :)

Regards,
Randy Burgess
Sr. Web Applications Developer
Nuvox Communications



> From: Martin Gainty <[EMAIL PROTECTED]>
> Reply-To: Struts Users Mailing List <user@struts.apache.org>
> Date: Mon, 14 Apr 2008 21:50:15 -0400
> To: Struts Users Mailing List <user@struts.apache.org>
> Subject: Re: [S2] Spring: Interceptors, prototype or singleton?
> 
> Could you provide a scenario where one bean is injected into another?
> 
> Thanks
> M-
> ----- Original Message -----
> From: "Randy Burgess" <[EMAIL PROTECTED]>
> To: "Struts Users Mailing List" <user@struts.apache.org>
> Sent: Monday, April 14, 2008 3:55 PM
> Subject: Re: [S2] Spring: Interceptors, prototype or singleton?
> 
> 
>> So the interceptor would have to be declared at the action level in this
>> case then? If I have a spring bean named myBean that is default scope and
> I
>> inject another bean declared as a prototype into it, the injected bean
> will
>> still be a singleton since there will be only one instance of myBean.
>> 
>> Regards,
>> Randy Burgess
>> Sr. Web Applications Developer
>> Nuvox Communications
>> 
>> 
>> 
>>> From: Don Brown <[EMAIL PROTECTED]>
>>> Reply-To: Struts Users Mailing List <user@struts.apache.org>
>>> Date: Tue, 15 Apr 2008 01:12:49 +1000
>>> To: Struts Users Mailing List <user@struts.apache.org>
>>> Subject: Re: [S2] Spring: Interceptors, prototype or singleton?
>>> 
>>> To clarify, interceptors aren't technically singletons as each
>>> instance in an interceptor stack gets its own interceptor instance.
>>> However, for all requests using that stack, the same interceptor will
>>> be used.  Therefore, you do need to be careful.  For example, most
>>> interceptors take parameters that configure their use within the
>>> stack, like the "validation" interceptor that takes a list of excluded
>>> methods from validation.  Interceptors can be configured at the stack
>>> level or at the action level.  If at the action level, you will get a
>>> unique interceptor instance for that action.
>>> 
>>> If you want Spring to construct your interceptor, I recommend the
>>> prototype scope, so that Struts gets a new instance of the interceptor
>>> as expected.
>>> 
>>> Don
>>> 
>>> On Tue, Apr 15, 2008 at 12:48 AM, Randy Burgess <[EMAIL PROTECTED]>
> wrote:
>>>> Interceptors are Singletons according to the documentation. If it were
> me I
>>>>  would come up with another method besides Spring for changing object
>>>>  properties.
>>>> 
>>>>  Regards,
>>>>  Randy Burgess
>>>>  Sr. Web Applications Developer
>>>>  Nuvox Communications
>>>> 
>>>> 
>>>> 
>>>>> From: GF <[EMAIL PROTECTED]>
>>>>> Reply-To: Struts Users Mailing List <user@struts.apache.org>
>>>>> Date: Mon, 14 Apr 2008 14:51:25 +0200
>>>>> To: Struts Users ML <user@struts.apache.org>
>>>>> Subject: [S2] Spring: Interceptors, prototype or singleton?
>>>> 
>>>> 
>>>>> 
>>>>> In a guide I found on the web, the interceptor was defined as
> singleton in
>>>>> the Spring's ApplicationContext.
>>>>> 
>>>>> If I need to use "changeable" object properties, I need to have it as
>>>>> Prototype, otherwise different requests will result in a object
> property
>>>>> overwriting.
>>>>> Is there any issues about defining an interceptor as Prototype, or is
> it ok?
>>>>> 
>>>>> Thanks
>>>>> 
>>>>> GF
>>>> 
>>>> 
>>>> 
>>>>  This email and any attachments ("Message") may contain legally
> privileged
>>>> and/or confidential information.  If you are not the addressee, or if
> this
>>>> Message has been addressed to you in error, you are not authorized to
> read,
>>>> copy, or distribute it, and we ask that you please delete it (including
> all
>>>> copies) and notify the sender by return email.  Delivery of this
> Message to
>>>> any person other than the intended recipient(s) shall not be deemed a
> waiver
>>>> of confidentiality and/or a privilege.
>>>> 
>>>> 
>>>>  This email and any attachments ("Message") may contain legally
> privileged
>>>> and/or confidential information.  If you are not the addressee, or if
> this
>>>> Message has been addressed to you in error, you are not authorized to
> read,
>>>> copy, or distribute it, and we ask that you please delete it (including
> all
>>>> copies) and notify the sender by return email.  Delivery of this
> Message to
>>>> any person other than the intended recipient(s) shall not be deemed a
> waiver
>>>> of confidentiality and/or a privilege.
>>>> 
>>>>  ---------------------------------------------------------------------
>>>>  To unsubscribe, e-mail: [EMAIL PROTECTED]
>>>>  For additional commands, e-mail: [EMAIL PROTECTED]
>>>> 
>>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>> 
>> 
>> 
>> 
>> This email and any attachments ("Message") may contain legally privileged
> and/or confidential information.  If you are not the addressee, or if this
> Message has been addressed to you in error, you are not authorized to read,
> copy, or distribute it, and we ask that you please delete it (including all
> copies) and notify the sender by return email.  Delivery of this Message to
> any person other than the intended recipient(s) shall not be deemed a waiver
> of confidentiality and/or a privilege.
>> 
>> 
>> This email and any attachments ("Message") may contain legally privileged
> and/or confidential information.  If you are not the addressee, or if this
> Message has been addressed to you in error, you are not authorized to read,
> copy, or distribute it, and we ask that you please delete it (including all
> copies) and notify the sender by return email.  Delivery of this Message to
> any person other than the intended recipient(s) shall not be deemed a waiver
> of confidentiality and/or a privilege.
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>> 
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 



This email and any attachments ("Message") may contain legally privileged 
and/or confidential information.  If you are not the addressee, or if this 
Message has been addressed to you in error, you are not authorized to read, 
copy, or distribute it, and we ask that you please delete it (including all 
copies) and notify the sender by return email.  Delivery of this Message to any 
person other than the intended recipient(s) shall not be deemed a waiver of 
confidentiality and/or a privilege.


This email and any attachments ("Message") may contain legally privileged 
and/or confidential information.  If you are not the addressee, or if this 
Message has been addressed to you in error, you are not authorized to read, 
copy, or distribute it, and we ask that you please delete it (including all 
copies) and notify the sender by return email.  Delivery of this Message to any 
person other than the intended recipient(s) shall not be deemed a waiver of 
confidentiality and/or a privilege.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to