Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ServletContext and Spring MVC

How can I get the ServletContext inside an Interceptor in Spring MVC 3?

like image 734
Viren Pushpanayagam Avatar asked Apr 21 '11 04:04

Viren Pushpanayagam


People also ask

What is ServletContext in Spring?

It's used to wire the configurations from Spring beans together and use them for the application. Use ApplicationContext if you want to retrieve the information of Spring beans. Use ServletContext if you want to get/set attribute those shared to all Servlet.

What is ServletContext and ServletConfig in Spring?

ServletConfig is used by only single servlet to get configuration information, whereas ServletContext is used by multiple objects to get configuration information. ServletConfig object is one per servlet class and destroyed once the servlet execution is completed.

Can we use multiple dispatcher servlet in Spring MVC?

You can have as many DispatcherServlets as you want. Basically what you need to do is duplicate the configuration and give the servlet a different name (else it will overwrite the previous one), and have some separate configuration classes (or xml files) for it.


1 Answers

Since interceptor is a bean, you can simply autowire it:

@Autowired ServletContext context; 
like image 72
axtavt Avatar answered Sep 19 '22 03:09

axtavt