Skip to content

@twasink /SpringMappingFilter.java
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Example Filter that binds spring-managed beans into the request
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.XmlWebApplicationContext;
public class SpringMappingFilter implements Filter {
private ServletContext context;
public void destroy() { }
public void init(FilterConfig filterConfig) {
this.context = filterConfig.getServletContext();
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filter)
throws IOException, ServletException {
// the Spring Context would have been configured by the SpringContextListener
ApplicationContext springContext = this.context.getAttribute(XmlWebApplicationContext.DEFAULT_CONFIG_LOCATION);
request.setAttribute("myBean", springContext.getBean("myBean");
filterChain.doFilter(request, response);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.