You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by dusty <du...@yahoo.com> on 2009/01/26 05:58:16 UTC

Spring Scope Default

When using the struts2-spring-plugin, without bean declaration for your
actions, what is the default scope for the created Action beans?  Prototype,
I hope, but I can't really find where that is set or happens.  I know the
default for Spring beans when not otherwise specified is Singleton, so I am
curious how the plugin gets the prototype scope in this instance.

The setup is:

* ContextLoaderListener in web.xml
* struts2-spring-plugin declared in maven
* actions configured as such in struts.xml
<action name="show" class="com.full.package.Action" method="show">
....
</action>
* No Spring bean configuration for actions in XML or annotations.

What is the scope of the created actions?  How do you test/prove that?

There are other variations that I wonder about:
* Bean definition for action in XML but with no "scope='prototype'"
* struts2-spring-plugin in path

Which one wins?  This seems like it should be a singleton since your XML
config should override any "auto" behavior of the plugin, but are we sure?

* @Component annotation on your action (with spring configured to find bean
annotations in that package)
* No @Scope annotation on the action bean
* struts2-spring-plugin in path
Probably singleton, right?
-- 
View this message in context: http://www.nabble.com/Spring-Scope-Default-tp21660528p21660528.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: Spring Scope Default

Posted by dusty <du...@yahoo.com>.
It would be interesting indeed if the Struts2 spring integration was really
just a re-badged Spring MVC application....

I so dislike magic, but I agree it works.


newton.dave wrote:
> 
> Isn't... that for a Spring MVC app?
> 
> Dave
> 
> Martin Gainty wrote:
>> your ActionController class extends MultiActionController as seen here..
>> /**
>>  * MultiActionController for the image list/upload UI.
>>  * @author Juergen Hoeller
>>  * @since 07.01.2004
>>  */
>> public class ImageController extends MultiActionController {
>> 
>> where /WEB-INF/web.xml contains:
>>     <!--
>>       - Spring web MVC servlet that dispatches request to registered
>> handlers.
>>       - Has its own application context, by default defined in
>> "{servlet-name}-servlet.xml",
>>       - i.e. "image-servlet.xml" in this case.
>>       -
>>       - A web app can contain any number of such servlets.
>>       - Note that this web app has a shared root application context,
>> serving as parent
>>       - of all DispatcherServlet contexts.
>>       -->
>>     <servlet>
>>         <servlet-name>image</servlet-name>
>>        
>> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
>>         <load-on-startup>2</load-on-startup>
>>     </servlet>
>> 
>> .......where {servlet-name}-servlet.xml contains.......
>> <?xml version="1.0" encoding="UTF-8"?>
>> <!--
>>   - DispatcherServlet application context for the image database.
>>   -->
>> <beans xmlns="http://www.springframework.org/schema/beans"
>>         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> xmlns:context="http://www.springframework.org/schema/context"
>>         xsi:schemaLocation="http://www.springframework.org/schema/beans
>> http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
>>                 http://www.springframework.org/schema/context
>> http://www.springframework.org/schema/context/spring-context-2.5.xsd">
>> 
>>     <!-- Activates @Autowired for ImageController -->
>>     <context:annotation-config/>
>> 
>>     <!-- MultiActionController that defines user interface actions as
>> separate methods -->
>>     <bean id="imageController"
>> class="org.springframework.samples.imagedb.web.ImageController"/>
>> 
>> 
>> HTH
>> Martin 
>> 
>> ______________________________________________ 
>> Disclaimer and confidentiality note 
>> Everything in this e-mail and any attachments relates to the official
>> business of Sender. This transmission is of a confidential nature and
>> Sender does not endorse distribution to any party other than intended
>> recipient. Sender does not necessarily endorse content contained within
>> this transmission. 
>> 
>> 
>> 
>> 
>>> Date: Mon, 26 Jan 2009 21:41:21 +0100
>>> Subject: Re: Spring Scope Default
>>> From: lukasz.lenart@googlemail.com
>>> To: user@struts.apache.org
>>>
>>> 2009/1/26 dusty <du...@yahoo.com>:
>>>> Interesting.  So I am being lazy by not looking at the code first; How
>>>> does
>>>> it register the new action object with Spring so its services can be
>>>> autowired in?
>>> I don't know exactly but it works ;-)
>>>
>>>
>>> Regards
>>> -- 
>>> Lukasz
>>> http://www.lenart.org.pl/
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>> 
>> _________________________________________________________________
>> Windows Live™ Hotmail®…more than just e-mail. 
>> http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t2_hm_justgotbetter_howitworks_012009
> 
> 
> ---------------------------------------------------------------------
> 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/Spring-Scope-Default-tp21660528p21679347.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: Spring Scope Default

Posted by Dave Newton <ne...@yahoo.com>.
Isn't... that for a Spring MVC app?

Dave

Martin Gainty wrote:
> your ActionController class extends MultiActionController as seen here..
> /**
>  * MultiActionController for the image list/upload UI.
>  * @author Juergen Hoeller
>  * @since 07.01.2004
>  */
> public class ImageController extends MultiActionController {
> 
> where /WEB-INF/web.xml contains:
>     <!--
>       - Spring web MVC servlet that dispatches request to registered handlers.
>       - Has its own application context, by default defined in "{servlet-name}-servlet.xml",
>       - i.e. "image-servlet.xml" in this case.
>       -
>       - A web app can contain any number of such servlets.
>       - Note that this web app has a shared root application context, serving as parent
>       - of all DispatcherServlet contexts.
>       -->
>     <servlet>
>         <servlet-name>image</servlet-name>
>         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
>         <load-on-startup>2</load-on-startup>
>     </servlet>
> 
> .......where {servlet-name}-servlet.xml contains.......
> <?xml version="1.0" encoding="UTF-8"?>
> <!--
>   - DispatcherServlet application context for the image database.
>   -->
> <beans xmlns="http://www.springframework.org/schema/beans"
>         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
>         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
>                 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
> 
>     <!-- Activates @Autowired for ImageController -->
>     <context:annotation-config/>
> 
>     <!-- MultiActionController that defines user interface actions as separate methods -->
>     <bean id="imageController" class="org.springframework.samples.imagedb.web.ImageController"/>
> 
> 
> HTH
> Martin 
> 
> ______________________________________________ 
> Disclaimer and confidentiality note 
> Everything in this e-mail and any attachments relates to the official business of Sender. This transmission is of a confidential nature and Sender does not endorse distribution to any party other than intended recipient. Sender does not necessarily endorse content contained within this transmission. 
> 
> 
> 
> 
>> Date: Mon, 26 Jan 2009 21:41:21 +0100
>> Subject: Re: Spring Scope Default
>> From: lukasz.lenart@googlemail.com
>> To: user@struts.apache.org
>>
>> 2009/1/26 dusty <du...@yahoo.com>:
>>> Interesting.  So I am being lazy by not looking at the code first; How does
>>> it register the new action object with Spring so its services can be
>>> autowired in?
>> I don't know exactly but it works ;-)
>>
>>
>> Regards
>> -- 
>> Lukasz
>> http://www.lenart.org.pl/
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
> 
> _________________________________________________________________
> Windows Live™ Hotmail®…more than just e-mail. 
> http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t2_hm_justgotbetter_howitworks_012009


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


RE: Spring Scope Default

Posted by Martin Gainty <mg...@hotmail.com>.
your ActionController class extends MultiActionController as seen here..
/**
 * MultiActionController for the image list/upload UI.
 * @author Juergen Hoeller
 * @since 07.01.2004
 */
public class ImageController extends MultiActionController {

where /WEB-INF/web.xml contains:
    <!--
      - Spring web MVC servlet that dispatches request to registered handlers.
      - Has its own application context, by default defined in "{servlet-name}-servlet.xml",
      - i.e. "image-servlet.xml" in this case.
      -
      - A web app can contain any number of such servlets.
      - Note that this web app has a shared root application context, serving as parent
      - of all DispatcherServlet contexts.
      -->
    <servlet>
        <servlet-name>image</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>2</load-on-startup>
    </servlet>

.......where {servlet-name}-servlet.xml contains.......
<?xml version="1.0" encoding="UTF-8"?>
<!--
  - DispatcherServlet application context for the image database.
  -->
<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">

    <!-- Activates @Autowired for ImageController -->
    <context:annotation-config/>

    <!-- MultiActionController that defines user interface actions as separate methods -->
    <bean id="imageController" class="org.springframework.samples.imagedb.web.ImageController"/>


HTH
Martin 

______________________________________________ 
Disclaimer and confidentiality note 
Everything in this e-mail and any attachments relates to the official business of Sender. This transmission is of a confidential nature and Sender does not endorse distribution to any party other than intended recipient. Sender does not necessarily endorse content contained within this transmission. 




> Date: Mon, 26 Jan 2009 21:41:21 +0100
> Subject: Re: Spring Scope Default
> From: lukasz.lenart@googlemail.com
> To: user@struts.apache.org
> 
> 2009/1/26 dusty <du...@yahoo.com>:
> > Interesting.  So I am being lazy by not looking at the code first; How does
> > it register the new action object with Spring so its services can be
> > autowired in?
> 
> I don't know exactly but it works ;-)
> 
> 
> Regards
> -- 
> Lukasz
> http://www.lenart.org.pl/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 

_________________________________________________________________
Windows Live™ Hotmail®…more than just e-mail. 
http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t2_hm_justgotbetter_howitworks_012009

Re: Spring Scope Default

Posted by Lukasz Lenart <lu...@googlemail.com>.
2009/1/26 dusty <du...@yahoo.com>:
> Interesting.  So I am being lazy by not looking at the code first; How does
> it register the new action object with Spring so its services can be
> autowired in?

I don't know exactly but it works ;-)


Regards
-- 
Lukasz
http://www.lenart.org.pl/

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


Re: Spring Scope Default

Posted by dusty <du...@yahoo.com>.


Lukasz Lenart wrote:
> 
> 2009/1/26 dusty <du...@yahoo.com>:
>> When using the struts2-spring-plugin, without bean declaration for your
>> actions, what is the default scope for the created Action beans? 
>> Prototype,
>> I hope, but I can't really find where that is set or happens.  I know the
>> default for Spring beans when not otherwise specified is Singleton, so I
>> am
>> curious how the plugin gets the prototype scope in this instance.
>>
>> The setup is:
>>
>> * ContextLoaderListener in web.xml
>> * struts2-spring-plugin declared in maven
>> * actions configured as such in struts.xml
>> <action name="show" class="com.full.package.Action" method="show">
>> ....
>> </action>
>> * No Spring bean configuration for actions in XML or annotations.
>>
>> What is the scope of the created actions?  How do you test/prove that?
> 
> In such way, when Spring is not able to create an action (no bean
> defintion), standard Struts2 ObjectFactory is used instead, which will
> create action for each request.
> 

Interesting.  So I am being lazy by not looking at the code first; How does
it register the new action object with Spring so its services can be
autowired in?
-- 
View this message in context: http://www.nabble.com/Spring-Scope-Default-tp21660528p21668715.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: Spring Scope Default

Posted by Lukasz Lenart <lu...@googlemail.com>.
2009/1/26 dusty <du...@yahoo.com>:
> When using the struts2-spring-plugin, without bean declaration for your
> actions, what is the default scope for the created Action beans?  Prototype,
> I hope, but I can't really find where that is set or happens.  I know the
> default for Spring beans when not otherwise specified is Singleton, so I am
> curious how the plugin gets the prototype scope in this instance.
>
> The setup is:
>
> * ContextLoaderListener in web.xml
> * struts2-spring-plugin declared in maven
> * actions configured as such in struts.xml
> <action name="show" class="com.full.package.Action" method="show">
> ....
> </action>
> * No Spring bean configuration for actions in XML or annotations.
>
> What is the scope of the created actions?  How do you test/prove that?

In such way, when Spring is not able to create an action (no bean
defintion), standard Struts2 ObjectFactory is used instead, which will
create action for each request.

> There are other variations that I wonder about:
> * Bean definition for action in XML but with no "scope='prototype'"
> * struts2-spring-plugin in path
>
> Which one wins?  This seems like it should be a singleton since your XML
> config should override any "auto" behavior of the plugin, but are we sure?

Singleton

> * @Component annotation on your action (with spring configured to find bean
> annotations in that package)
> * No @Scope annotation on the action bean
> * struts2-spring-plugin in path
> Probably singleton, right?

IMHO, yes.


Regards
-- 
Lukasz
http://www.lenart.org.pl/

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