Question

We Know the Spring Framework gives singleton, prototype, request, session, global_session bean Scopes.

Also we know that Spring web flow gives flowScope,viewScope,requestScope,flashScope,conversationScope.

So If i mentioned one Component, say Student, as @Component @Scope=singleton in a spring MVC project. For each request, will it create a new Student Object or Spring container will create only once?

Was it helpful?

Solution

You are confusing yourself with objects and beans.

For each request, will it create a new Student Object or Spring container will create only once?

The functioning of Spring is purely using beans. When you declare a something like a @Component, it's just an annotation that tells Spring that the part you've declared as a component is either Model or View or Controller i.e. a component of MVC. When you say something like @Scope=singleton, it tells Spring that only a single object instance can access the bean.

Let me make it more clear. Say you and I are objects and a strawberry candy is a bean. So if you have the candy. I cannot take it from you. Meaning only one of us can have that candy. It's the same thing with singleton scope.

Hope I made things simpler.. :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top