Take the 2-minute tour ×

In my Spring-MMVC application,

I have a xx-servlet.xml corresponding to my dispatcher servlet- Defines my web layer beans/classes and importing another context.xml which defines all persistence layer bean/services.

In xx-servlet.xml,

have defined a ApplicationContextProvider class which implements ApplicationcontextAware interface.

and have annotated all my beans (presentation objects) with @Component and when needed getting the instance of these beans from ApplicationContext (not using WebApplicationContext).

So, in this case what would be the scope of my beans?

Also, What would be the case if I use WebApplicationContext?

What would be the best practice... use ApplicationContext or WebApplicationContext?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

WebApplicationContext adds more scopes (request, session, globalSession) to the standard Application context (which only provides Singleton and Prototype scopes). If you do not specify a bean scope it will be by default Singleton scope.

The best practice is if you are in a web environment you should be using WebApplicationContext so you can use those additional scopes and ServletContextAware beans. But if you don't use them then it's up to you.

Besides that, most spring mvc infrastructure beans need a WebApplicationContext.

share|improve this answer
add comment

Your Answer


