Java tutorial
/* * Copyright (C) 2010-2111 sunjumper@163.com * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package jrouter.servlet.filter; import javax.servlet.FilterConfig; import jrouter.ActionFactory; import org.springframework.web.context.support.WebApplicationContextUtils; /** * ActionFactoryspringframeworkbean * ActionFactorybean??springActionFactoryspring */ public class SpringBeanJRouterFilter extends SpringJRouterFilter { /** * ActionFactoryspringframeworkbean?? */ private String beanName; @Override public void init(FilterConfig filterConfig) { beanName = filterConfig.getInitParameter("beanName"); if (beanName != null) log.info("Set bean's name of springframework : " + beanName); super.init(filterConfig); } /** * ActionFactoryspringbean * * @param filterConfig ? * * @return ActionFactory bean. */ @Override protected ActionFactory createActionFactory(FilterConfig filterConfig) { //set ActionFactory with spring bean return beanName == null ? WebApplicationContextUtils.getRequiredWebApplicationContext(filterConfig.getServletContext()) .getBean(ActionFactory.class) : WebApplicationContextUtils.getRequiredWebApplicationContext(filterConfig.getServletContext()) .getBean(beanName, ActionFactory.class); } }