1

This is my web.xml

<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:/spring/root-context.xml</param-value>
</context-param>

<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- Processes application requests -->
<servlet>
    <servlet-name>dispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:/spring/servlet-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>dispatcherServlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

And my Custom Filter like this.


protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
                throws ServletException, IOException {
    WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
    //wac is root context, not dispatcherServlet's context   
}

I want to get dispatcherServlet's context(servlet-context.xml).

please help me

이현규
  • 97
  • 1
  • 7

1 Answers1

0

i din't tested but you can try this check in spring docs

DispatcherServlet ds = new DispatcherServlet(request.getServletContext())
Narendra
  • 127
  • 3
  • 11