Spring @Scope

in Spring frameworks, sometimes you need to take control of beans scope, in that case you can add AOP jar files which will come if you use BOM, and Context set of dependencies and then easily use the @Scope annotation on beans. Below is a set of bean scope available in Spring:

  • Singleton = only one object in entire Spring container
  • prototype = a new object per every time calling applicationContext.getBean(…)
  • web based bean scope:
    • request // a new object per request – a little bit longer than prototype since that was being called by getbean method every time.
    • session // an object per session and will be renewed whenever we hit the timeout for that session
    • globalsession // an object for entire application



@scope("singleton") // this is the default bean scope
//or using this @Scope(ConfirgurableFactoryBean.SCOPE_SINGLETON)

public class MyServiceImple extends MyService{






Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s