0 votes
in Spring by

How to get ServletContext and ServletConfig object in a Spring Bean?

1 Answer

0 votes
by

There are two ways to get Container specific objects in the spring bean.

Implementing Spring *Aware interfaces, for these ServletContextAware and ServletConfigAware interfaces, for complete example of these aware interfaces, please read Spring Aware Interfaces

Using @Autowired annotation with bean variable of type ServletContext and ServletConfig. They will work only in servlet container specific environment only though.

@Autowired

ServletContext servletContext;

...