We can set the request attributes using Model
or ModelAndView
object in Spring.
We can use @SessionAttributes
to keep attributes in session scope.
Then how can I put an attribute in application
scope in Spring, does spring has provided any annotation for that?
When you mention about storing your model at application scope then I would conclude you wish to store it at the ServletContext level. For doing that you need to make your controller implements ServletContextAware interface.
After getting access to ServletContext you can add it as a attribute
Kindly let me know if this is what you are looking for.
In the spring you can get application scope by using @Autowired annotation
Then you can access you element by using .getAttribute Method
Basically all that is needed to configure an application scope is to use the
ServletContext
, and you can do it in Spring as follows:javax.servlet.ServletContext
could be even injected to your bean implementation as follows: