通过shirofilter加载到spring原理简析
1、org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext#selfInitialize //web容器初始化执行bean初始化
private void selfInitialize(ServletContext servletContext) throws ServletException {
prepareWebApplicationContext(servletContext);
ConfigurableListableBeanFactory beanFactory = getBeanFactory();
ExistingWebApplicationScopes existingScopes = new ExistingWebApplicationScopes(
beanFactory);
WebApplicationContextUtils.registerWebApplicationScopes(beanFactory,
getServletContext());
existingScopes.restore();
WebApplicationContextUtils.registerEnvironmentBeans(beanFactory,
getServletContext());
for (ServletContextInitializer beans : getServletContextInitializerBeans()) {
beans.onStartup(servletContext);//启动servlet上下文初始化bean,这里会注册filter类
}
}
2、org.springframework.boot.web.servlet.ServletContextInitializerBeans#ServletContextInitializerBeans//启动web容器时获取所有servlet上下文初始化bean,
3、org.springframework.boot.web.servlet.ServletContextInitializerBeans#addAdaptableBeans //这里装配适配bean
private void addAdaptableBeans(ListableBeanFactory beanFactory) {
MultipartConfigElement multipartConfig = getMultipartConfig(beanFactory);
addAsRegistrationBean(beanFactory, Servlet.class,
new ServletRegistrationBeanAdapter(multipartConfig));
addAsRegistrationBean(beanFactory, Filter.class,
new FilterRegistrationBeanAdapter());//这里就会执行加载实现了filter接口的类
for (Class<?> listenerType : ServletListenerRegistrationBean
.getSupportedTypes()) {
addAsRegistrationBean(beanFactory, EventListener.class,
(Class<EventListener>) listenerType,
new ServletListenerRegistrationBeanAdapter());
}
}
4、org.springframework.boot.web.servlet.ServletContextInitializerBeans#addAsRegistrationBean(org.springframework.beans.factory.ListableBeanFactory, java.lang.Class<T>, java.lang.Class<B>, org.springframework.boot.web.servlet.ServletContextInitializerBeans.RegistrationBeanAdapter<T>)
5、org.springframework.boot.web.servlet.ServletContextInitializerBeans#getOrderedBeansOfType(org.springframework.beans.factory.ListableBeanFactory, java.lang.Class<T>, java.util.Set<?>) //进一步查找bean
6、org.springframework.beans.factory.support.DefaultListableBeanFactory#doGetBeanNamesForType //获取实现filter接口的类
//spring怎么知道ShiroFilterFactoryBean创建的是filter接口类型的对象呢,因为ShiroFilterFactoryBean这里有个方法
public Class getObjectType() {
return SpringShiroFilter.class;
}
//这里就告诉了spring了ShiroFilterFactoryBean是创建
7、org.springframework.boot.web.servlet.ServletContextInitializerBeans#getOrderedBeansOfType//创建SpringShiroFilter对象并放到map中
8、beans.onStartup(servletContext); org.apache.catalina.core.StandardContext#addFilterDef//添加filter到web容器。
基于springmvc拦截器与过滤器执行顺序
https://blog.csdn.net/zxd1435513775/article/details/80556034
org.springframework.boot.SpringApplication#refreshContext该类启动时刷新上下文,
org.springframework.context.support.AbstractApplicationContext#refresh spring的核心类,包括类扫描与装配
org.springframework.beans.factory.xml.XmlBeanDefinitionReader springxml配置bean的读取类