Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

Spring prototype scope

Ranch Hand
Posts: 246
Firefox Browser Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
Posts: 17346
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

What does a metric clock look like? I bet it is nothing like this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic