singleton="false" - always gives med singleton objects

39 views
Skip to first unread message

olav69

unread,
Mar 3, 2010, 12:26:22 PM3/3/10
to ColdSpring-Users
Coldspring aleays gives med singleton object even if I use the
singleton="false" attributes. Why?

Brian Kotek

unread,
Mar 3, 2010, 1:01:55 PM3/3/10
to coldspri...@googlegroups.com
Singleton="false" should give you a new instance each time getBean() is called. If you have a simple test case that demonstrates a bug with this, please send it over.

That said, most users have ColdSpring managage singletons. It is not optimized for transient objects due to the performance cost of dependency resolution. If you want to manage non-singletons, the common solution is to have your own factory for these (and the factory is a singleton), since if gives you much more control over how the objects are created.

On Wed, Mar 3, 2010 at 12:26 PM, olav69 <ol...@ansit.no> wrote:
Coldspring aleays gives med singleton object even if I use the
singleton="false" attributes. Why?

--
You received this message because you are subscribed to the Google Groups "ColdSpring-Users" group.
To post to this group, send email to coldspri...@googlegroups.com.
To unsubscribe from this group, send email to coldspring-use...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/coldspring-users?hl=en.


ol...@ansit.no

unread,
Mar 8, 2010, 6:57:00 AM3/8/10
to coldspri...@googlegroups.com
I'm using the SvefakturaV1p0Message object to handle messages I receive,
but the errorcollection accumulates from message to message. This indicates
that ColdSpring doesn't give me a new clean object each time I request a
SvefakturaV1p0Message.


<beans>
<bean id="ErrorCollection" class="DropBox.dmc.message.errorcollection"
singleton="false"/>
<bean id="SvefakturaV1p0HogiaValistractor"
class="DropBox.dmc.message.SvefakturaV1p0HogiaValistractor"
singelton="false">
<constructor-arg name="errorCollectionObject">
<ref bean="ErrorCollection"/>
</constructor-arg>
</bean>
<bean id="ValidateOrgNrNo" class="DropBox.dmc.message.ValidateOrgNrNo"/>
<bean id="SvefakturaV1p0Message" class="DropBox.dmc.message.Message"
singleton="false">
<constructor-arg name="dropboxCompanyId">
<value>2</value>
</constructor-arg>
<constructor-arg name="OrgNrValidator">
<ref bean="ValidateOrgNrNo"/>
</constructor-arg>
<constructor-arg name="Valistractor">
<ref bean="SvefakturaV1p0Hogia"/>
</constructor-arg>
</bean>
</beans>

coldspring-use...@googlegroups.com<coldspring-users%2Bunsu...@googlegroups.com>

Kevan Stannard

unread,
Mar 8, 2010, 7:39:58 AM3/8/10
to coldspri...@googlegroups.com
Looks like you have a typo for your SvefakturaV1p0HogiaValistractor bean:

<bean id="SvefakturaV1p0HogiaValistractor" class="DropBox.dmc.message.SvefakturaV1p0HogiaValistractor" singelton="false">

Should be

<bean id="SvefakturaV1p0HogiaValistractor" class="DropBox.dmc.message.SvefakturaV1p0HogiaValistractor" singleton="false">


To unsubscribe from this group, send email to coldspring-use...@googlegroups.com.

ol...@ansit.no

unread,
Mar 8, 2010, 10:16:57 AM3/8/10
to coldspri...@googlegroups.com
Desperation drove me to try different spelling variants of singleton :-)


The following configuration works fine

<bean id="SvefakturaV1p0Valistractor"
class="DropBox.dmc.message.SvefakturaV1p0Valistractor" singleton="false">


<constructor-arg name="errorCollectionObject">
<ref bean="ErrorCollection" />
</constructor-arg>
</bean>

But if I inject a logging service, the object starts acting as a
singleton.

<bean id="SvefakturaV1p0ValistractorTarget"
class="DropBox.dmc.message.SvefakturaV1p0Valistractor" singleton="false">


<constructor-arg name="errorCollectionObject">
<ref bean="ErrorCollection" />
</constructor-arg>
</bean>

<bean id="SvefakturaV1p0Valistractor"
class="coldspring.aop.framework.ProxyFactoryBean">
<property name="target">
<ref bean="SvefakturaV1p0ValistractorTarget" />
</property>
<property name="interceptorNames">
<list>
<value>loggingAdvisor</value>
</list>
</property>
</bean>


On Mon, 8 Mar 2010 23:39:58 +1100, Kevan Stannard
<kevans...@gmail.com>
wrote:


> Looks like you have a typo for your SvefakturaV1p0HogiaValistractor
bean:
>
> <bean
> id="SvefakturaV1p0HogiaValistractor"
> class="DropBox.dmc.message.SvefakturaV1p0HogiaValistractor"

> *singelton*="false">


>
> Should be
>
> <bean
> id="SvefakturaV1p0HogiaValistractor"
> class="DropBox.dmc.message.SvefakturaV1p0HogiaValistractor"

> *singleton*="false">

<coldspring-users%2Bunsu...@googlegroups.com<coldspring-users%252Buns...@googlegroups.com>

Dennis Clark

unread,
Mar 8, 2010, 11:59:17 AM3/8/10
to coldspri...@googlegroups.com
Your SvefakturaV1p0Valistractor bean is a singleton. If you inject a singleton bean with a property bean, the singleton bean gets only one instance of the property bean even if that property bean is defined as singleton="false".

You can see this for yourself by defining a second proxy bean and injecting the same <ref bean="SvefakturaV1p0ValistractorTarget" /> into it. If you change the state of the target object in the second bean, the target object of the first proxy bean will not be affected because they are different instances. However the target object instance assigned to each proxy bean will remain the same for the lifetime of the ColdSpring bean factory.

It looks like you are trying to apply ColdSpring AOP to transient objects. You might be able to get this to work by using singleton="false" on SvefakturaV1p0Valistractor, but even if this works instantiating each object is going to be incredibly slow as the dependency resolution that Brian mentioned would occur twice for each call to getBean("SvefakturaV1p0Valistractor") (once for the proxy and again for the target).

I suggest you explore the idea of writing your own custom factory for your transients. The factory could either inject a logging service into your transients before returning them, or it could create its own proxy objects that implement AOP-style advice on behalf of your transients.

Cheers,

-- Dennis

Brian Kotek

unread,
Mar 8, 2010, 1:14:05 PM3/8/10
to coldspri...@googlegroups.com
I'm still inclined to believe that the issue is with your setup and not with ColdSpring. That said, if you think it's a bug and you can create a simple 2 or 3 file test case that demonstrates the issue, please send it to the list so that we can take a look.

thanks,

Brian

On Mon, Mar 8, 2010 at 10:16 AM, <ol...@ansit.no> wrote:

ol...@ansit.no

unread,
Mar 8, 2010, 6:44:28 PM3/8/10
to coldspri...@googlegroups.com
Dennis, your absolutely right when it comes to the lack of speed.

But I still don't understand why I don't get a non-singleton as soon as I
inject a logging service when I define the bean as

<bean id="SvefakturaV1p0ValistractorTarget"
class="DropBox.dmc.message.SvefakturaV1p0Valistractor" singleton="false">
<constructor-arg name="errorCollectionObject">
<ref bean="ErrorCollection" />
</constructor-arg>
</bean>
<bean id="SvefakturaV1p0Valistractor"
class="coldspring.aop.framework.ProxyFactoryBean">
<property name="target">
<ref bean="SvefakturaV1p0ValistractorTarget" />
</property>
<property name="interceptorNames">
<list>
<value>loggingAdvisor</value>
</list>
</property>
</bean>

Why does injecting a loggingadvisor break my non-singleton object?


This works as a charm and gives me a non-singleton

<bean id="SvefakturaV1p0Valistractor"
class="DropBox.dmc.message.SvefakturaV1p0Valistractor" singleton="false">
<constructor-arg name="errorCollectionObject">
<ref bean="ErrorCollection" />
</constructor-arg>
</bean>

Cheers,
Olav

On Mon, 8 Mar 2010 11:59:17 -0500, Dennis Clark <boom...@gmail.com>
wrote:


> Your SvefakturaV1p0Valistractor bean is a singleton. If you inject a
> singleton bean with a property bean, the singleton bean gets only one
> instance of the property bean even if that property bean is defined as
> singleton="false".
>
> You can see this for yourself by defining a second proxy bean and
injecting
> the same <ref bean="SvefakturaV1p0ValistractorTarget" /> into it. If you
> change the state of the target object in the second bean, the target
object
> of the first proxy bean will not be affected because they are different
> instances. However the target object instance assigned to each proxy
bean
> will remain the same for the lifetime of the ColdSpring bean factory.
>
> It looks like you are trying to apply ColdSpring AOP to transient
objects.

> You *might* be able to get this to work by using singleton="false" on


> SvefakturaV1p0Valistractor,
> but even if this works instantiating each object is going to be
incredibly
> slow as the dependency resolution that Brian mentioned would occur

> *twice*for each call to getBean("

ol...@ansit.no

unread,
Mar 8, 2010, 6:56:09 PM3/8/10
to coldspri...@googlegroups.com
I'm inclined to believe that the issue is related to my limited
knowledge/understanding of ColdSpring :-)

But I'm trying to find out if it's possible to inject a loggingadvisor
into a non-singleton object, and still expect the returned proxy to be a
non-singleton? If this should be possible, either my setup is wrong (most
likely) or there might be a bug related to the ProxyFactoryBean returning
non-singleton objects.

Cheers,
Olav

Brian Kotek

unread,
Mar 8, 2010, 7:33:00 PM3/8/10
to coldspri...@googlegroups.com
Maybe I'm missing it in the discussion, but what happens if you set the bean you're creating using ProxyFactoryBean to singleton="false"?

--
You received this message because you are subscribed to the Google Groups "ColdSpring-Users" group.
To post to this group, send email to coldspri...@googlegroups.com.
To unsubscribe from this group, send email to coldspring-use...@googlegroups.com.

Sean Corfield

unread,
Mar 21, 2010, 2:27:51 PM3/21/10
to coldspri...@googlegroups.com
I didn't see a conclusion to this after Brian's suggestion so I'll reiterate:

On Mon, Mar 8, 2010 at 4:44 PM, <ol...@ansit.no> wrote:
> <bean id="SvefakturaV1p0Valistractor"
> class="coldspring.aop.framework.ProxyFactoryBean">

This defines a singleton. You want SvefakturaV1p0Valistractor to be a
transient so you need singleton="false" here as Brian suggested.

Did that work?
--
Sean A Corfield -- (904) 302-SEAN
Railo Technologies US -- http://getrailo.com/
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

Reply all
Reply to author
Forward
0 new messages