shiro整合到spring原理

通過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的讀取類

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章