Reputation: 7551
try to autowired ServletConfig
into current application, not ServletContext
because an API ask for it.
I know user can get ServletContext by a ServletConfig servlet but how to do the other way around or taken from spring application
Upvotes: 0
Views: 3883
Reputation: 2096
Rather than autowiring, trying implementing ServletConfigAware.
Edit:
I couldn't find an example that shows using ServletConfigAware in a real project. Essentially, you'd have a class that implemented this interface to obtain the ServletConfig.
You'd create a Spring bean from the class by annotating the class with @Component or declaring a bean in XML. When Spring creates the bean, it would invoke setServletConfig(ServletConfig servletConfig)
.
Once you had an instance of ServletConfig in your bean, you'd do whatever you need with it.
Your question was how to obtain the ServletConfig, but I think (correct me if I'm wrong) you are looking to integrate a legacy Servlet into your Spring Web MVC application. ServletWrappingController might be a better choice. I haven't ever used it myself, but it appears to be specifically designed for that purpose.
Upvotes: 2