This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
I am new to Spring and I have question regarding to the prototype scope of a bean.
I have a simple program, and i have a simple bean called helloworld which has a prototype scope.
Even though its scope defined as prototype; it did not created a new instance each times the bean is called.
I thought it should create a new instance every time it is called.
I was running this program in eclipse.
Here is my simple code. Please help me to point out my errors if you could.
Many thanks in advance.
and the result when i ran the program:
I don't know why its showed the same message twice as it was singleton. I thought it should shown Hello world on the first line and null on the second line.
Its going to print it twice you have it defined in your bean
What proto-type does is it does not use a singleton. That bean is created new each time you ask for it. To prove this add a default constructor to your HelloWorld object
You will see that the constructor is called twice. Once each time you get the bean. Now if you remove the prototype it will only print once. This is because it is instantiated only once as a singleton and you get that same instance on each request.