This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Spring and the fly likes Spring prototype scope Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring prototype scope" Watch "Spring prototype scope" New topic

Spring prototype scope

mallikarjun dontamsetti
Ranch Hand

Joined: Mar 18, 2011
Posts: 243

Hi i am learning spring framework i came across the scope in tutorial that i am reading it said that if we declare a scope as prototype spring container create a new object for that class each time. so i have written a program to test it but no luck. could any one please help me. My code is

Main class

Shape interface has a method draw() which is implemented by Circle class

Point class is fallow

My spring configuration file is as fallows

The bean references are printing
same (which should be different because it is prototype)
from sysout. And one more thing how to configure a bean(point) that i set a message specifically to it to the particular class(center).
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17249

Bean circle is a Singleton, you have

<bean id="circle" class="org.malli.Circle" >
<property name="center" ref="zeroPoint"/>


Which means the zeroPoint injected into that circle will be just one zeroPoint and always that same zeroPoint. It won't get a new one each time because Circle is created only once and its center property will only be set once. So therefore the life of the circle, which is the entire application duration will always point to the same zeroPoint assigned when it was created.


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
I agree. Here's the link:
subject: Spring prototype scope
Similar Threads
Pointcut methods
where is the pointcut in this example
spring AOP doesn't work
unable to call AOP method
where is the pointcut in this example?