标签:conf header xml文件 ide mvc ade utils web getbean
public class ClientSessionFilter implements Filter { private static Logger log = Logger.getLogger(ClientSessionFilter.class); @Autowired private RequestData requestData; //我们想要注入的bean @Override public void init(FilterConfig filterConfig) throws ServletException { } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { ObjectMapper mapper = new ObjectMapper(); HttpServletRequest httpServletReq = (HttpServletRequest) request; String session = httpServletReq.getHeader("S"); ClientSession cs; if(StringUtils.isNotBlank(session)) { try { cs = mapper.readValue(session, ClientSession.class); } catch (Exception e) { log.error("Session序列化错误" + e); throw new BusinessException(401, "Session序列化错误"); } if(log.isDebugEnabled()) { log.debug(cs); } requestData.setClientSession(cs); } chain.doFilter(request, response); } @Override public void destroy() { } }
<bean id="requestData" scope="request" class="cn.ucmed.common.cache.RequestData"> <aop:scoped-proxy/> //这个标签可以参考上一遍博客 </bean> <bean id="clientSessionFilter" class="cn.ucmed.baseline.d2d.filter.ClientSessionFilter" />
<filter> <filter-name>filterProxy</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> <async-supported>true</async-supported> <init-param> <param-name>targetBeanName</param-name> <param-value>clientSessionFilter</param-value> </init-param> <init-param> <param-name>targetFilterLifecycle</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>filterProxy</filter-name> <url-pattern>/registeryuyue/*</url-pattern> </filter-mapping>
SpringMVC的filter怎么使用Autowired依赖注入bean
标签:conf header xml文件 ide mvc ade utils web getbean
原文地址:http://www.cnblogs.com/happyflyingpig/p/7998449.html