struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Martin Gainty" <mgai...@hotmail.com>
Subject Re: [S2] Spring: Interceptors, prototype or singleton?
Date Mon, 14 Apr 2008 15:51:27 GMT
I assume you're speaking of the capabilities of the spring-plugin?
http://struts.apache.org/2.x/docs/spring-plugin.html

A very good article on Spring BeanFactory scope parameters can be found
here:
http://www.theserverside.com/tt/articles/article.tss?l=IntrotoSpring25
where Bean Factory scope is defined to be:
a.. Singleton: in this case, there's one shared instance of the object with
a particular name, which will be retrieved on lookup. This is the default,
and most often used, mode. It's ideal for stateless service objects.
a.. Prototype or non-singleton: in this case, each retrieval will result in
the creation of an independent object. For example, this could be used to
allow each caller to have a distinct object reference.
a.. Custom object "scopes", which typically interact with a store outside
the control of the container. Some of these come out of the box, such as
request and session (for web applications). Others come with third party
products, such as clustered caches. It is easy to define custom scopes in
the event that none of those provided out of the box is sufficient, through
implementing a simple interface.

Once you've committed to BeanFactory scope as either (shared) singleton or
(distinct object reference) prototype
there is no ability to change scope from then on

in /WEB-INF/web.xml you might have a way to determine the
applicationContext.xml file location such as what is displayed here
<context-param>
    <param-name>contextConfigLocation</param-name>

<param-value>/WEB-INF/applicationContext-*.xml,classpath*:applicationContext
-*.xml</param-value>
</context-param>

Simplest case for ./WEB-INF/applicationContext.xml configuration where bean
is declared as prototype (singleton="false")
<beans default-autowire="autodetect">
    <bean id="bar" class="com.my.BarClass" singleton="false"/>
</beans>

The autowire property of struts.objectFactory.spring.autoWire is a bit
tricky as for Bean Dependency Injection you will
need an exact match on name, or class-type or constructor

HTH
Martin
----- Original Message -----
From: "GF" <ganfab@gmail.com>
To: "Struts Users ML" <user@struts.apache.org>
Sent: Monday, April 14, 2008 8:51 AM
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
>


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


Mime
View raw message