久久福利_99r_国产日韩在线视频_直接看av的网站_中文欧美日韩_久久一

您的位置:首頁技術文章
文章詳情頁

基于SpringBoot核心原理(自動配置、事件驅動、Condition)

瀏覽:3日期:2023-04-30 08:40:37

前言

SpringBoot是Spring的包裝,通過自動配置使得SpringBoot可以做到開箱即用,上手成本非常低,但是學習其實現原理的成本大大增加,需要先了解熟悉Spring原理。如果還不清楚Spring原理的,可以先查看博主之前的文章,本篇主要分析SpringBoot的啟動、自動配置、Condition、事件驅動原理。

正文

啟動原理

SpringBoot啟動非常簡單,因其內置了Tomcat,所以只需要通過下面幾種方式啟動即可:

@SpringBootApplication(scanBasePackages = {'cn.dark'})public class SpringbootDemo { public static void main(String[] args) { // 第一種 SpringApplication.run(SpringbootDemo .class, args); // 第二種 new SpringApplicationBuilder(SpringbootDemo .class)).run(args); // 第三種 SpringApplication springApplication = new SpringApplication(SpringbootDemo.class); springApplication.run(); }}

可以看到第一種是最簡單的,也是最常用的方式,需要注意類上面需要標注@SpringBootApplication注解,這是自動配置的核心實現,稍后分析,先來看看SpringBoot啟動做了些什么?

在往下之前,不妨先猜測一下,run方法中需要做什么?對比Spring源碼,我們知道,Spring的啟動都會創建一個ApplicationContext的應用上下文對象,并調用其refresh方法啟動容器,SpringBoot只是Spring的一層殼,肯定也避免不了這樣的操作。

另一方面,以前通過Spring搭建的項目,都需要打成War包發布到Tomcat才行,而現在SpringBoot已經內置了Tomcat,只需要打成Jar包啟動即可,所以在run方法中肯定也會創建對應的Tomcat對象并啟動。

以上只是我們的猜想,下面就來驗證,進入run方法:

public ConfigurableApplicationContext run(String... args) { // 統計時間用的工具類 StopWatch stopWatch = new StopWatch(); stopWatch.start(); ConfigurableApplicationContext context = null; Collection<SpringBootExceptionReporter> exceptionReporters = new ArrayList<>(); configureHeadlessProperty(); // 獲取實現了SpringApplicationRunListener接口的實現類,通過SPI機制加載 // META-INF/spring.factories文件下的類 SpringApplicationRunListeners listeners = getRunListeners(args); // 首先調用SpringApplicationRunListener的starting方法 listeners.starting(); try { ApplicationArguments applicationArguments = new DefaultApplicationArguments(args); // 處理配置數據 ConfigurableEnvironment environment = prepareEnvironment(listeners, applicationArguments); configureIgnoreBeanInfo(environment); // 啟動時打印banner Banner printedBanner = printBanner(environment); // 創建上下文對象 context = createApplicationContext(); // 獲取SpringBootExceptionReporter接口的類,異常報告 exceptionReporters = getSpringFactoriesInstances(SpringBootExceptionReporter.class, new Class[] { ConfigurableApplicationContext.class }, context); prepareContext(context, environment, listeners, applicationArguments, printedBanner); // 核心方法,啟動spring容器 refreshContext(context); afterRefresh(context, applicationArguments); // 統計結束 stopWatch.stop(); if (this.logStartupInfo) { new StartupInfoLogger(this.mainApplicationClass).logStarted(getApplicationLog(), stopWatch); } // 調用started listeners.started(context); // ApplicationRunner // CommandLineRunner // 獲取這兩個接口的實現類,并調用其run方法 callRunners(context, applicationArguments); } catch (Throwable ex) { handleRunFailure(context, ex, exceptionReporters, listeners); throw new IllegalStateException(ex); } try { // 最后調用running方法 listeners.running(context); } catch (Throwable ex) { handleRunFailure(context, ex, exceptionReporters, null); throw new IllegalStateException(ex); } return context; }

SpringBoot的啟動流程就是這個方法,先看getRunListeners方法,這個方法就是去拿到所有的SpringApplicationRunListener實現類,這些類是用于SpringBoot事件發布的,關于事件驅動稍后分析,這里主要看這個方法的實現原理:

private SpringApplicationRunListeners getRunListeners(String[] args) { Class<?>[] types = new Class<?>[] { SpringApplication.class, String[].class }; return new SpringApplicationRunListeners(logger, getSpringFactoriesInstances(SpringApplicationRunListener.class, types, this, args)); } private <T> Collection<T> getSpringFactoriesInstances(Class<T> type, Class<?>[] parameterTypes, Object... args) { ClassLoader classLoader = getClassLoader(); // Use names and ensure unique to protect against duplicates Set<String> names = new LinkedHashSet<>(SpringFactoriesLoader.loadFactoryNames(type, classLoader)); // 加載上來后反射實例化 List<T> instances = createSpringFactoriesInstances(type, parameterTypes, classLoader, args, names); AnnotationAwareOrderComparator.sort(instances); return instances; } public static List<String> loadFactoryNames(Class<?> factoryType, @Nullable ClassLoader classLoader) { String factoryTypeName = factoryType.getName(); return loadSpringFactories(classLoader).getOrDefault(factoryTypeName, Collections.emptyList()); } public static final String FACTORIES_RESOURCE_LOCATION = 'META-INF/spring.factories'; private static Map<String, List<String>> loadSpringFactories(@Nullable ClassLoader classLoader) { MultiValueMap<String, String> result = cache.get(classLoader); if (result != null) { return result; } try { Enumeration<URL> urls = (classLoader != null ? classLoader.getResources(FACTORIES_RESOURCE_LOCATION) : ClassLoader.getSystemResources(FACTORIES_RESOURCE_LOCATION)); result = new LinkedMultiValueMap<>(); while (urls.hasMoreElements()) { URL url = urls.nextElement(); UrlResource resource = new UrlResource(url); Properties properties = PropertiesLoaderUtils.loadProperties(resource); for (Map.Entry<?, ?> entry : properties.entrySet()) { String factoryTypeName = ((String) entry.getKey()).trim(); for (String factoryImplementationName : StringUtils.commaDelimitedListToStringArray((String) entry.getValue())) { result.add(factoryTypeName, factoryImplementationName.trim()); } } } cache.put(classLoader, result); return result; } }

一步步追蹤下去可以看到最終就是通過SPI機制根據接口類型從META-INF/spring.factories文件中加載對應的實現類并實例化,SpringBoot的自動配置也是這樣實現的。

為什么要這樣實現呢?通過注解掃描不可以么?當然不行,這些類都在第三方jar包中,注解掃描實現是很麻煩的,當然你也可以通過@Import注解導入,但是這種方式不適合擴展類特別多的情況,所以這里采用SPI的優點就顯而易見了。

回到run方法中,可以看到調用了createApplicationContext方法,見名知意,這個就是去創建應用上下文對象:

public static final String DEFAULT_SERVLET_WEB_CONTEXT_CLASS = 'org.springframework.boot.' + 'web.servlet.context.AnnotationConfigServletWebServerApplicationContext'; protected ConfigurableApplicationContext createApplicationContext() { Class<?> contextClass = this.applicationContextClass; if (contextClass == null) { try { switch (this.webApplicationType) { case SERVLET: contextClass = Class.forName(DEFAULT_SERVLET_WEB_CONTEXT_CLASS); break; case REACTIVE: contextClass = Class.forName(DEFAULT_REACTIVE_WEB_CONTEXT_CLASS); break; default: contextClass = Class.forName(DEFAULT_CONTEXT_CLASS); } } catch (ClassNotFoundException ex) { throw new IllegalStateException( 'Unable create a default ApplicationContext, please specify an ApplicationContextClass', ex); } } return (ConfigurableApplicationContext) BeanUtils.instantiateClass(contextClass); }

注意這里通過反射實例化了一個新的沒見過的上下文對象AnnotationConfigServletWebServerApplicationContext,這個是SpringBoot擴展的,看看其構造方法:

public AnnotationConfigServletWebServerApplicationContext() { this.reader = new AnnotatedBeanDefinitionReader(this); this.scanner = new ClassPathBeanDefinitionScanner(this); }

如果你有看過Spring注解驅動的實現原理,這兩個對象肯定不會陌生,一個實支持注解解析的,另外一個是掃描包用的。上下文創建好了,下一步自然就是調用refresh方法啟動容器:

private void refreshContext(ConfigurableApplicationContext context) { refresh(context); if (this.registerShutdownHook) { try { context.registerShutdownHook(); } catch (AccessControlException ex) { // Not allowed in some environments. } } } protected void refresh(ApplicationContext applicationContext) { Assert.isInstanceOf(AbstractApplicationContext.class, applicationContext); ((AbstractApplicationContext) applicationContext).refresh(); }

這里首先會調用到其父類中ServletWebServerApplicationContext:

public final void refresh() throws BeansException, IllegalStateException { try { super.refresh(); } catch (RuntimeException ex) { stopAndReleaseWebServer(); throw ex; } }

可以看到是直接委托給了父類:

public void refresh() throws BeansException, IllegalStateException { synchronized (this.startupShutdownMonitor) { // Prepare this context for refreshing. prepareRefresh(); // Tell the subclass to refresh the internal bean factory. ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory(); // Prepare the bean factory for use in this context. prepareBeanFactory(beanFactory); try { // Allows post-processing of the bean factory in context subclasses. postProcessBeanFactory(beanFactory); // Invoke factory processors registered as beans in the context. invokeBeanFactoryPostProcessors(beanFactory); // Register bean processors that intercept bean creation. registerBeanPostProcessors(beanFactory); // Initialize message source for this context. initMessageSource(); // Initialize event multicaster for this context. initApplicationEventMulticaster(); // Initialize other special beans in specific context subclasses. onRefresh(); // Check for listener beans and register them. registerListeners(); // Instantiate all remaining (non-lazy-init) singletons. finishBeanFactoryInitialization(beanFactory); // Last step: publish corresponding event. finishRefresh(); } catch (BeansException ex) { if (logger.isWarnEnabled()) { logger.warn('Exception encountered during context initialization - ' + 'cancelling refresh attempt: ' + ex); } // Destroy already created singletons to avoid dangling resources. destroyBeans(); // Reset ’active’ flag. cancelRefresh(ex); // Propagate exception to caller. throw ex; } finally { // Reset common introspection caches in Spring’s core, since we // might not ever need metadata for singleton beans anymore... resetCommonCaches(); } } }

這個方法不會陌生吧,之前已經分析過了,這里不再贅述,至此SpringBoot的容器就啟動了,但是Tomcat啟動是在哪里呢?run方法中也沒有看到。實際上Tomcat的啟動也是在refresh流程中,這個方法其中一步是調用了onRefresh方法,在Spring中這是一個沒有實現的模板方法,而SpringBoot就通過這個方法完成了Tomcat的啟動:

protected void onRefresh() { super.onRefresh(); try { createWebServer(); } catch (Throwable ex) { throw new ApplicationContextException('Unable to start web server', ex); } } private void createWebServer() { WebServer webServer = this.webServer; ServletContext servletContext = getServletContext(); if (webServer == null && servletContext == null) { ServletWebServerFactory factory = getWebServerFactory(); // 主要看這個方法 this.webServer = factory.getWebServer(getSelfInitializer()); } else if (servletContext != null) { try { getSelfInitializer().onStartup(servletContext); } catch (ServletException ex) { throw new ApplicationContextException('Cannot initialize servlet context', ex); } } initPropertySources(); }

這里首先拿到TomcatServletWebServerFactory對象,通過該對象再去創建和啟動Tomcat:

public WebServer getWebServer(ServletContextInitializer... initializers) { if (this.disableMBeanRegistry) { Registry.disableRegistry(); } Tomcat tomcat = new Tomcat(); File baseDir = (this.baseDirectory != null) ? this.baseDirectory : createTempDir('tomcat'); tomcat.setBaseDir(baseDir.getAbsolutePath()); Connector connector = new Connector(this.protocol); connector.setThrowOnFailure(true); tomcat.getService().addConnector(connector); customizeConnector(connector); tomcat.setConnector(connector); tomcat.getHost().setAutoDeploy(false); configureEngine(tomcat.getEngine()); for (Connector additionalConnector : this.additionalTomcatConnectors) { tomcat.getService().addConnector(additionalConnector); } prepareContext(tomcat.getHost(), initializers); return getTomcatWebServer(tomcat); }

上面的每一步都可以對比Tomcat的配置文件,需要注意默認只支持了http協議:

Connector connector = new Connector(this.protocol); private String protocol = DEFAULT_PROTOCOL; public static final String DEFAULT_PROTOCOL = 'org.apache.coyote.http11.Http11NioProtocol';

如果想要擴展的話則可以對additionalTomcatConnectors屬性設置值,需要注意這個屬性沒有對應的setter方法,只有addAdditionalTomcatConnectors方法,也就是說我們只能通過實現BeanFactoryPostProcessor接口的postProcessBeanFactory方法,而不能通過BeanDefinitionRegistryPostProcessor的postProcessBeanDefinitionRegistry方法,因為前者可以通過傳入的BeanFactory對象提前獲取到TomcatServletWebServerFactory對象調用addAdditionalTomcatConnectors即可;而后者只能拿到BeanDefinition對象,該對象只能通過setter方法設置值。

事件驅動

Spring原本就提供了事件機制,而在SpringBoot中又對其進行擴展,通過發布訂閱事件在容器的整個生命周期的不同階段進行不同的操作。我們先來看看SpringBoot啟動關閉的過程中默認會發布哪些事件,使用下面的代碼即可:

@SpringBootApplicationpublic class SpringEventDemo { public static void main(String[] args) { new SpringApplicationBuilder(SpringEventDemo.class) .listeners(event -> { System.err.println('接收到事件:' + event.getClass().getSimpleName()); }) .run() .close(); }}

這段代碼會在控制臺打印所有的事件名稱,按照順序如下:

ApplicationStartingEvent:容器啟動

ApplicationEnvironmentPreparedEvent:環境準備好

ApplicationContextInitializedEvent:上下文初始化完成

ApplicationPreparedEvent:上下文準備好

ContextRefreshedEvent:上下文刷新完

ServletWebServerInitializedEvent:webServer初始化完成

ApplicationStartedEvent:容器啟動完成

ApplicationReadyEvent:容器就緒

ContextClosedEvent:容器關閉

以上是正常啟動關閉,如果發生異常還有發布ApplicationFailedEvent事件。事件的發布遍布在整個容器的啟動關閉周期中,事件發布對象剛剛我們也看到了是通過SPI加載的SpringApplicationRunListener實現類EventPublishingRunListener,同樣事件監聽器也是在spring.factories文件中配置的,默認實現了以下監聽器:

org.springframework.context.ApplicationListener=org.springframework.boot.ClearCachesApplicationListener,org.springframework.boot.builder.ParentContextCloserApplicationListener,org.springframework.boot.cloud.CloudFoundryVcapEnvironmentPostProcessor,org.springframework.boot.context.FileEncodingApplicationListener,org.springframework.boot.context.config.AnsiOutputApplicationListener,org.springframework.boot.context.config.ConfigFileApplicationListener,org.springframework.boot.context.config.DelegatingApplicationListener,org.springframework.boot.context.logging.ClasspathLoggingApplicationListener,org.springframework.boot.context.logging.LoggingApplicationListener,org.springframework.boot.liquibase.LiquibaseServiceLocatorApplicationListener

可以看到有用于文件編碼的(FileEncodingApplicationListener),有加載日志框架的(LoggingApplicationListener),還有加載配置的(ConfigFileApplicationListener)等等一系列監聽器,SpringBoot也就是通過這系列監聽器將必要的配置和組件加載到容器中來,這里不再詳細分析,感興趣的讀者可以通過其實現的onApplicationEvent方法看到每個監聽器究竟是監聽的哪一個事件,當然事件發布和監聽我們自己也是可以擴展的。

自動配置原理

SpringBoot最核心的還是自動配置,為什么它能做到開箱即用,不再需要我們手動使用@EnableXXX等注解來開啟?這一切的答案就在@SpringBootApplication注解中:

@Target(ElementType.TYPE)@Retention(RetentionPolicy.RUNTIME)@Documented@Inherited@SpringBootConfiguration@EnableAutoConfiguration@ComponentScan(excludeFilters = { @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class), @Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })public @interface SpringBootApplication {}

這里重要的注解有三個:@SpringBootConfiguration、@EnableAutoConfiguration、@ComponentScan。@ComponentScan就不用再說了,@SpringBootConfiguration等同于@Configuration,而@EnableAutoConfiguration就是開啟自動配置:

@AutoConfigurationPackage@Import(AutoConfigurationImportSelector.class)public @interface EnableAutoConfiguration {}@Import(AutoConfigurationPackages.Registrar.class)public @interface AutoConfigurationPackage {}

@AutoConfigurationPackage注解的作用就是將該注解所標記類所在的包作為自動配置的包,簡單看看就行,主要看AutoConfigurationImportSelector,這個就是實現自動配置的核心類,注意這個類是實現的DeferredImportSelector接口。在這個類中有一個selectImports方法。

這個方法在我之前的文章這一次搞懂Spring事務注解的解析也有分析過,只是實現類不同,它同樣會被ConfigurationClassPostProcessor類調用,先來看這個方法做了些什么:

public String[] selectImports(AnnotationMetadata annotationMetadata) { if (!isEnabled(annotationMetadata)) { return NO_IMPORTS; } AutoConfigurationMetadata autoConfigurationMetadata = AutoConfigurationMetadataLoader .loadMetadata(this.beanClassLoader); // 獲取所有的自動配置類 AutoConfigurationEntry autoConfigurationEntry = getAutoConfigurationEntry(autoConfigurationMetadata, annotationMetadata); return StringUtils.toStringArray(autoConfigurationEntry.getConfigurations()); } protected AutoConfigurationEntry getAutoConfigurationEntry(AutoConfigurationMetadata autoConfigurationMetadata, AnnotationMetadata annotationMetadata) { if (!isEnabled(annotationMetadata)) { return EMPTY_ENTRY; } AnnotationAttributes attributes = getAttributes(annotationMetadata); // SPI獲取EnableAutoConfiguration為key的所有實現類 List<String> configurations = getCandidateConfigurations(annotationMetadata, attributes); configurations = removeDuplicates(configurations); Set<String> exclusions = getExclusions(annotationMetadata, attributes); checkExcludedClasses(configurations, exclusions); configurations.removeAll(exclusions); // 把某些自動配置類過濾掉 configurations = filter(configurations, autoConfigurationMetadata); fireAutoConfigurationImportEvents(configurations, exclusions); // 包裝成自動配置實體類 return new AutoConfigurationEntry(configurations, exclusions); } protected List<String> getCandidateConfigurations(AnnotationMetadata metadata, AnnotationAttributes attributes) { // SPI獲取EnableAutoConfiguration為key的所有實現類 List<String> configurations = SpringFactoriesLoader.loadFactoryNames(getSpringFactoriesLoaderFactoryClass(), getBeanClassLoader()); Assert.notEmpty(configurations, 'No auto configuration classes found in META-INF/spring.factories. If you ' + 'are using a custom packaging, make sure that file is correct.'); return configurations; }

追蹤源碼最終可以看到也是從META-INF/spring.factories文件中拿到所有EnableAutoConfiguration對應的值(在spring-boot-autoconfigure中)并通過反射實例化,過濾后包裝成AutoConfigurationEntry對象返回。

看到這里你應該會覺得自動配置的實現就是通過這個selectImports方法,但實際上這個方法通常并不會被調用到,而是會調用該類的內部類AutoConfigurationGroup的process和selectImports方法,前者同樣是通過getAutoConfigurationEntry拿到所有的自動配置類,而后者這是過濾排序并包裝后返回。

下面就來分析ConfigurationClassPostProcessor是怎么調用到這里的,直接進入processConfigBeanDefinitions方法:

public void processConfigBeanDefinitions(BeanDefinitionRegistry registry) { List<BeanDefinitionHolder> configCandidates = new ArrayList<>(); String[] candidateNames = registry.getBeanDefinitionNames(); for (String beanName : candidateNames) { BeanDefinition beanDef = registry.getBeanDefinition(beanName); if (beanDef.getAttribute(ConfigurationClassUtils.CONFIGURATION_CLASS_ATTRIBUTE) != null) { if (logger.isDebugEnabled()) { logger.debug('Bean definition has already been processed as a configuration class: ' + beanDef); } } else if (ConfigurationClassUtils.checkConfigurationClassCandidate(beanDef, this.metadataReaderFactory)) { configCandidates.add(new BeanDefinitionHolder(beanDef, beanName)); } } // Return immediately if no @Configuration classes were found if (configCandidates.isEmpty()) { return; } // Sort by previously determined @Order value, if applicable configCandidates.sort((bd1, bd2) -> { int i1 = ConfigurationClassUtils.getOrder(bd1.getBeanDefinition()); int i2 = ConfigurationClassUtils.getOrder(bd2.getBeanDefinition()); return Integer.compare(i1, i2); }); // Detect any custom bean name generation strategy supplied through the enclosing application context SingletonBeanRegistry sbr = null; if (registry instanceof SingletonBeanRegistry) { sbr = (SingletonBeanRegistry) registry; if (!this.localBeanNameGeneratorSet) { BeanNameGenerator generator = (BeanNameGenerator) sbr.getSingleton( AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR); if (generator != null) { this.componentScanBeanNameGenerator = generator; this.importBeanNameGenerator = generator; } } } if (this.environment == null) { this.environment = new StandardEnvironment(); } // Parse each @Configuration class ConfigurationClassParser parser = new ConfigurationClassParser( this.metadataReaderFactory, this.problemReporter, this.environment, this.resourceLoader, this.componentScanBeanNameGenerator, registry); Set<BeanDefinitionHolder> candidates = new LinkedHashSet<>(configCandidates); Set<ConfigurationClass> alreadyParsed = new HashSet<>(configCandidates.size()); do { parser.parse(candidates); parser.validate(); Set<ConfigurationClass> configClasses = new LinkedHashSet<>(parser.getConfigurationClasses()); configClasses.removeAll(alreadyParsed); // Read the model and create bean definitions based on its content if (this.reader == null) { this.reader = new ConfigurationClassBeanDefinitionReader( registry, this.sourceExtractor, this.resourceLoader, this.environment, this.importBeanNameGenerator, parser.getImportRegistry()); } this.reader.loadBeanDefinitions(configClasses); alreadyParsed.addAll(configClasses); // 省略。。。。 }

前面一大段主要是拿到合格的Configuration配置類,主要邏輯是在ConfigurationClassParser.parse方法中,該方法完成了對@Component、@Bean、@Import、@ComponentScans等注解的解析,這里主要看對@Import的解析,其它的讀者可自行分析。

一步步追蹤,最終會進入到processConfigurationClass方法:

protected void processConfigurationClass(ConfigurationClass configClass) throws IOException { if (this.conditionEvaluator.shouldSkip(configClass.getMetadata(), ConfigurationPhase.PARSE_CONFIGURATION)) { return; } ConfigurationClass existingClass = this.configurationClasses.get(configClass); if (existingClass != null) { if (configClass.isImported()) { if (existingClass.isImported()) { existingClass.mergeImportedBy(configClass); } // Otherwise ignore new imported config class; existing non-imported class overrides it. return; } else { // Explicit bean definition found, probably replacing an import. // Let’s remove the old one and go with the new one. this.configurationClasses.remove(configClass); this.knownSuperclasses.values().removeIf(configClass::equals); } } // Recursively process the configuration class and its superclass hierarchy. SourceClass sourceClass = asSourceClass(configClass); do { sourceClass = doProcessConfigurationClass(configClass, sourceClass); } while (sourceClass != null); this.configurationClasses.put(configClass, configClass); }

這里需要注意this.conditionEvaluator.shouldSkip方法的調用,這個方法就是進行Bean加載過濾的,即根據@Condition注解的匹配值判斷是否加載該Bean,具體實現稍后分析,繼續跟蹤主流程doProcessConfigurationClass:

protected final SourceClass doProcessConfigurationClass(ConfigurationClass configClass, SourceClass sourceClass) throws IOException { 省略.... // Process any @Import annotations processImports(configClass, sourceClass, getImports(sourceClass), true); 省略.... return null; }

這里就是完成對一系列注解的支撐,我省略掉了,主要看processImports方法,這個方法就是處理@Import注解的:

private void processImports(ConfigurationClass configClass, SourceClass currentSourceClass, Collection<SourceClass> importCandidates, boolean checkForCircularImports) { if (importCandidates.isEmpty()) { return; } if (checkForCircularImports && isChainedImportOnStack(configClass)) { this.problemReporter.error(new CircularImportProblem(configClass, this.importStack)); } else { this.importStack.push(configClass); try { for (SourceClass candidate : importCandidates) { if (candidate.isAssignable(ImportSelector.class)) { // Candidate class is an ImportSelector -> delegate to it to determine imports Class<?> candidateClass = candidate.loadClass(); ImportSelector selector = ParserStrategyUtils.instantiateClass(candidateClass, ImportSelector.class, this.environment, this.resourceLoader, this.registry); if (selector instanceof DeferredImportSelector) { this.deferredImportSelectorHandler.handle(configClass, (DeferredImportSelector) selector); } else { String[] importClassNames = selector.selectImports(currentSourceClass.getMetadata()); Collection<SourceClass> importSourceClasses = asSourceClasses(importClassNames); processImports(configClass, currentSourceClass, importSourceClasses, false); } } else if (candidate.isAssignable(ImportBeanDefinitionRegistrar.class)) { Class<?> candidateClass = candidate.loadClass(); ImportBeanDefinitionRegistrar registrar = ParserStrategyUtils.instantiateClass(candidateClass, ImportBeanDefinitionRegistrar.class, this.environment, this.resourceLoader, this.registry); configClass.addImportBeanDefinitionRegistrar(registrar, currentSourceClass.getMetadata()); } else { this.importStack.registerImport( currentSourceClass.getMetadata(), candidate.getMetadata().getClassName()); processConfigurationClass(candidate.asConfigClass(configClass)); } } } } }

剛剛我提醒過AutoConfigurationImportSelector是實現DeferredImportSelector接口的,如果不是該接口的實現類則是直接調用selectImports方法,反之則是調用DeferredImportSelectorHandler.handle方法:

private List<DeferredImportSelectorHolder> deferredImportSelectors = new ArrayList<>(); public void handle(ConfigurationClass configClass, DeferredImportSelector importSelector) { DeferredImportSelectorHolder holder = new DeferredImportSelectorHolder( configClass, importSelector); if (this.deferredImportSelectors == null) { DeferredImportSelectorGroupingHandler handler = new DeferredImportSelectorGroupingHandler(); handler.register(holder); handler.processGroupImports(); } else { this.deferredImportSelectors.add(holder); } }

首先創建了一個DeferredImportSelectorHolder對象,如果是第一次執行則是添加到deferredImportSelectors屬性中,等到ConfigurationClassParser.parse的最后調用process方法:

public void parse(Set<BeanDefinitionHolder> configCandidates) { 省略..... this.deferredImportSelectorHandler.process(); } public void process() { List<DeferredImportSelectorHolder> deferredImports = this.deferredImportSelectors; this.deferredImportSelectors = null; try { if (deferredImports != null) { DeferredImportSelectorGroupingHandler handler = new DeferredImportSelectorGroupingHandler(); deferredImports.sort(DEFERRED_IMPORT_COMPARATOR); deferredImports.forEach(handler::register); handler.processGroupImports(); } } finally { this.deferredImportSelectors = new ArrayList<>(); } }

反之則是直接執行,首先通過register拿到AutoConfigurationGroup對象:

public void register(DeferredImportSelectorHolder deferredImport) { Class<? extends Group> group = deferredImport.getImportSelector() .getImportGroup(); DeferredImportSelectorGrouping grouping = this.groupings.computeIfAbsent( (group != null ? group : deferredImport), key -> new DeferredImportSelectorGrouping(createGroup(group))); grouping.add(deferredImport); this.configurationClasses.put(deferredImport.getConfigurationClass().getMetadata(), deferredImport.getConfigurationClass()); } public Class<? extends Group> getImportGroup() { return AutoConfigurationGroup.class; }

然后在processGroupImports方法中進行真正的處理:

public void processGroupImports() { for (DeferredImportSelectorGrouping grouping : this.groupings.values()) { grouping.getImports().forEach(entry -> { ConfigurationClass configurationClass = this.configurationClasses.get( entry.getMetadata()); try { processImports(configurationClass, asSourceClass(configurationClass), asSourceClasses(entry.getImportClassName()), false); } catch (BeanDefinitionStoreException ex) { throw ex; } catch (Throwable ex) { throw new BeanDefinitionStoreException( 'Failed to process import candidates for configuration class [' + configurationClass.getMetadata().getClassName() + ']', ex); } }); } } public Iterable<Group.Entry> getImports() { for (DeferredImportSelectorHolder deferredImport : this.deferredImports) { this.group.process(deferredImport.getConfigurationClass().getMetadata(), deferredImport.getImportSelector()); } return this.group.selectImports(); }

在getImports方法中就完成了對process和selectImports方法的調用,拿到自動配置類后再遞歸調用調用processImports方法完成對自動配置類的加載。

至此,自動配置的加載過程就分析完了,下面是時序圖:

基于SpringBoot核心原理(自動配置、事件驅動、Condition)

Condition注解原理

在自動配置類中有很多Condition相關的注解,以AOP為例:

Configuration(proxyBeanMethods = false)@ConditionalOnProperty(prefix = 'spring.aop', name = 'auto', havingValue = 'true', matchIfMissing = true)public class AopAutoConfiguration { @Configuration(proxyBeanMethods = false) @ConditionalOnClass(Advice.class) static class AspectJAutoProxyingConfiguration { @Configuration(proxyBeanMethods = false) @EnableAspectJAutoProxy(proxyTargetClass = false) @ConditionalOnProperty(prefix = 'spring.aop', name = 'proxy-target-class', havingValue = 'false', matchIfMissing = false) static class JdkDynamicAutoProxyConfiguration { } @Configuration(proxyBeanMethods = false) @EnableAspectJAutoProxy(proxyTargetClass = true) @ConditionalOnProperty(prefix = 'spring.aop', name = 'proxy-target-class', havingValue = 'true', matchIfMissing = true) static class CglibAutoProxyConfiguration { } } @Configuration(proxyBeanMethods = false) @ConditionalOnMissingClass('org.aspectj.weaver.Advice') @ConditionalOnProperty(prefix = 'spring.aop', name = 'proxy-target-class', havingValue = 'true', matchIfMissing = true) static class ClassProxyingConfiguration { ClassProxyingConfiguration(BeanFactory beanFactory) { if (beanFactory instanceof BeanDefinitionRegistry) { BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory; AopConfigUtils.registerAutoProxyCreatorIfNecessary(registry); AopConfigUtils.forceAutoProxyCreatorToUseClassProxying(registry); } } }}

這里就能看到@ConditionalOnProperty、@ConditionalOnClass、@ConditionalOnMissingClass,另外還有@ConditionalOnBean、@ConditionalOnMissingBean等等很多條件匹配注解。這些注解表示條件匹配才會加載該Bean,以@ConditionalOnProperty為例,表明配置文件中符合條件才會加載對應的Bean,prefix表示在配置文件中的前綴,name表示配置的名稱,havingValue表示配置為該值時才匹配,matchIfMissing則是表示沒有該配置是否默認加載對應的Bean。

其它注解可類比理解記憶,下面主要來分析該注解的實現原理。

這里注解點進去看會發現每個注解上都標注了@Conditional注解,并且value值都對應一個類,比如OnBeanCondition,而這些類都實現了Condition接口,看看其繼承體系:

基于SpringBoot核心原理(自動配置、事件驅動、Condition)

上面只展示了幾個實現類,但實際上Condition的實現類是非常多的,我們還可以自己實現該接口來擴展@Condition注解。

Condition接口中有一個matches方法,這個方法返回true則表示匹配。該方法在ConfigurationClassParser中多處都有調用,也就是剛剛我提醒過的shouldSkip方法,具體實現是在ConditionEvaluator類中:

public boolean shouldSkip(@Nullable AnnotatedTypeMetadata metadata, @Nullable ConfigurationPhase phase) { if (metadata == null || !metadata.isAnnotated(Conditional.class.getName())) { return false; } if (phase == null) { if (metadata instanceof AnnotationMetadata && ConfigurationClassUtils.isConfigurationCandidate((AnnotationMetadata) metadata)) { return shouldSkip(metadata, ConfigurationPhase.PARSE_CONFIGURATION); } return shouldSkip(metadata, ConfigurationPhase.REGISTER_BEAN); } List<Condition> conditions = new ArrayList<>(); for (String[] conditionClasses : getConditionClasses(metadata)) { for (String conditionClass : conditionClasses) { Condition condition = getCondition(conditionClass, this.context.getClassLoader()); conditions.add(condition); } } AnnotationAwareOrderComparator.sort(conditions); for (Condition condition : conditions) { ConfigurationPhase requiredPhase = null; if (condition instanceof ConfigurationCondition) { requiredPhase = ((ConfigurationCondition) condition).getConfigurationPhase(); } if ((requiredPhase == null || requiredPhase == phase) && !condition.matches(this.context, metadata)) { return true; } } return false; }

再來看看matches的實現,但OnBeanCondition類中沒有實現該方法,而是在其父類SpringBootCondition中:

public final boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { String classOrMethodName = getClassOrMethodName(metadata); try { ConditionOutcome outcome = getMatchOutcome(context, metadata); logOutcome(classOrMethodName, outcome); recordEvaluation(context, classOrMethodName, outcome); return outcome.isMatch(); }

getMatchOutcome方法也是一個模板方法,具體的匹配邏輯就在這個方法中實現,該方法返回的ConditionOutcome對象就包含了是否匹配和日志消息兩個字段。進入到OnBeanCondition類中:

public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { ConditionMessage matchMessage = ConditionMessage.empty(); MergedAnnotations annotations = metadata.getAnnotations(); if (annotations.isPresent(ConditionalOnBean.class)) { Spec<ConditionalOnBean> spec = new Spec<>(context, metadata, annotations, ConditionalOnBean.class); MatchResult matchResult = getMatchingBeans(context, spec); if (!matchResult.isAllMatched()) { String reason = createOnBeanNoMatchReason(matchResult); return ConditionOutcome.noMatch(spec.message().because(reason)); } matchMessage = spec.message(matchMessage).found('bean', 'beans').items(Style.QUOTE, matchResult.getNamesOfAllMatches()); } if (metadata.isAnnotated(ConditionalOnSingleCandidate.class.getName())) { Spec<ConditionalOnSingleCandidate> spec = new SingleCandidateSpec(context, metadata, annotations); MatchResult matchResult = getMatchingBeans(context, spec); if (!matchResult.isAllMatched()) { return ConditionOutcome.noMatch(spec.message().didNotFind('any beans').atAll()); } else if (!hasSingleAutowireCandidate(context.getBeanFactory(), matchResult.getNamesOfAllMatches(), spec.getStrategy() == SearchStrategy.ALL)) { return ConditionOutcome.noMatch(spec.message().didNotFind('a primary bean from beans') .items(Style.QUOTE, matchResult.getNamesOfAllMatches())); } matchMessage = spec.message(matchMessage).found('a primary bean from beans').items(Style.QUOTE, matchResult.getNamesOfAllMatches()); } if (metadata.isAnnotated(ConditionalOnMissingBean.class.getName())) { Spec<ConditionalOnMissingBean> spec = new Spec<>(context, metadata, annotations, ConditionalOnMissingBean.class); MatchResult matchResult = getMatchingBeans(context, spec); if (matchResult.isAnyMatched()) { String reason = createOnMissingBeanNoMatchReason(matchResult); return ConditionOutcome.noMatch(spec.message().because(reason)); } matchMessage = spec.message(matchMessage).didNotFind('any beans').atAll(); } return ConditionOutcome.match(matchMessage); }

可以看到該類支持了@ConditionalOnBean、@ConditionalOnSingleCandidate、@ConditionalOnMissingBean注解,主要的匹配邏輯在getMatchingBeans方法中:

protected final MatchResult getMatchingBeans(ConditionContext context, Spec<?> spec) { ClassLoader classLoader = context.getClassLoader(); ConfigurableListableBeanFactory beanFactory = context.getBeanFactory(); boolean considerHierarchy = spec.getStrategy() != SearchStrategy.CURRENT; Set<Class<?>> parameterizedContainers = spec.getParameterizedContainers(); if (spec.getStrategy() == SearchStrategy.ANCESTORS) { BeanFactory parent = beanFactory.getParentBeanFactory(); Assert.isInstanceOf(ConfigurableListableBeanFactory.class, parent, 'Unable to use SearchStrategy.ANCESTORS'); beanFactory = (ConfigurableListableBeanFactory) parent; } MatchResult result = new MatchResult(); Set<String> beansIgnoredByType = getNamesOfBeansIgnoredByType(classLoader, beanFactory, considerHierarchy, spec.getIgnoredTypes(), parameterizedContainers); for (String type : spec.getTypes()) { Collection<String> typeMatches = getBeanNamesForType(classLoader, considerHierarchy, beanFactory, type, parameterizedContainers); typeMatches.removeAll(beansIgnoredByType); if (typeMatches.isEmpty()) { result.recordUnmatchedType(type); } else { result.recordMatchedType(type, typeMatches); } } for (String annotation : spec.getAnnotations()) { Set<String> annotationMatches = getBeanNamesForAnnotation(classLoader, beanFactory, annotation, considerHierarchy); annotationMatches.removeAll(beansIgnoredByType); if (annotationMatches.isEmpty()) { result.recordUnmatchedAnnotation(annotation); } else { result.recordMatchedAnnotation(annotation, annotationMatches); } } for (String beanName : spec.getNames()) { if (!beansIgnoredByType.contains(beanName) && containsBean(beanFactory, beanName, considerHierarchy)) { result.recordMatchedName(beanName); } else { result.recordUnmatchedName(beanName); } } return result; }

這里邏輯看起來比較復雜,但實際上就做了兩件事,首先通過getNamesOfBeansIgnoredByType方法調用beanFactory.getBeanNamesForType拿到容器中對應的Bean實例,然后根據返回的結果判斷哪些Bean存在,哪些Bean不存在(Condition注解中是可以配置多個值的)并返回MatchResult對象,而MatchResult中只要有一個Bean沒有匹配上就返回false,也就決定了當前Bean是否需要實例化。

總結

本篇分析了SpringBoot核心原理的實現,通過本篇相信讀者也將能更加熟練地使用和擴展SpringBoot。另外還有一些常用的組件我沒有展開分析,如事務、MVC、監聽器的自動配置,這些我們有了Spring源碼基礎的話下來看一下就明白了,這里就不贅述了。最后讀者可以思考一下我們應該如何自定義starter啟動器,相信看完本篇應該難不倒你。

以上這篇基于SpringBoot核心原理(自動配置、事件驅動、Condition)就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持好吧啦網。

標簽: Spring
相關文章:
主站蜘蛛池模板: 成人精品网 | 国产96在线观看 | 国产伦精品一区二区三区高清 | 91电影在线 | 成人a在线视频免费观看 | 国产精品欧美一区二区三区 | 99视频精品| 人人爱夜夜爽日日视频 | 亚洲欧洲无码一区二区三区 | 国产欧美精品区一区二区三区 | 国产精品成人国产乱一区 | 亚洲国产精品一区二区久久 | 亚洲精品久久久久久一区二区 | 国产宾馆自拍 | 国产精品久久九九 | 精品久久久久久久久久久久久久久 | 一区二区亚洲 | 中文字幕第66页 | 成人在线不卡 | 久久综合一区二区三区 | 天堂一区| 国产美女一区二区 | 国产亚洲精品成人av久久影院 | 成人免费视频一区二区 | 亚洲国产精品一区二区久久 | av网站免费 | 久久久精品国产 | 国产一区二区h | 国产精品一区二区在线 | 极品av | 欧美一级片在线观看 | 国产日韩视频 | 精品免费国产视频 | 欧美美女爱爱视频 | 日韩字幕一区 | 亚洲精品一区二区三区蜜桃久 | 玖玖免费| 日韩一区免费观看 | 久久国产精品无码网站 | 成人av网页 | 午夜精品久久久久久久 | 51ⅴ精品国产91久久久久久 | 欧洲一级毛片 | 在线电影亚洲 | 黄色小视频在线观看 | 黄色av网站在线观看 | 国精品一区二区三区 | 欧美日韩一区二区在线观看 | 国产一区免费在线观看 | 国产羞羞视频在线观看 | 亚洲综合中文 | 日韩3级在线观看 | 在线免费91| 精品国产乱码久久久久久88av | 日韩一区二区在线观看 | 一级大片免费观看 | 欧美激情性国产欧美无遮挡 | 国产精品美女久久久久aⅴ国产馆 | 亚洲欧美国产一区二区 | 福利网站在线观看 | 精品一区二区国产 | a级网站在线观看 | 91精品国产综合久久久亚洲 | 久久久精品影院 | 国产色婷婷 | 国产精品三级在线 | 午夜色视频在线观看 | 国语av在线| 国产免费一级特黄录像 | 一区二区三区国产精品 | 亚州av| 毛片免费观看视频 | 日韩精品 电影一区 亚洲 | 久久综合av | 四虎影视 | 狠狠干美女| 夜夜春精品视频高清69式 | 色性网站 | 久久久精品 | 青娱乐网 | 91 久久| 亚洲欧美日韩精品 | 在线色网 | 91在线| 欧美专区在线 | 一区二区av| 国产一区二区三区免费在线观看 | 国产免费亚洲 | 国产精品久久久久久久午夜片 | 国产一区二区三区免费看 | 国产精品久久久久久久久免费高清 | 成人免费黄色片 | 亚洲精品国产第一综合99久久 | 亚洲欧洲精品一区二区三区 | 国产成人精品av | 亚洲在线播放 | 一级欧美日韩 | 亚洲一区 | 在线中文字幕av | 久久99国产精品久久99大师 | 午夜精品一区二区三区在线播放 | 在线观看91 | 国产精品成人3p一区二区三区 | 超碰在线91 | 六月婷操 | 亚洲h在线观看 | 欧美成人免费在线视频 | 在线国产一区二区 | 免费黄色在线观看 | 久久精品黄色 | 日韩不卡一区 | 色吧av| 国产不卡一二三区 | 亚洲深深色噜噜狠狠网站 | 欧美一区不卡 | www.亚洲精品 | 亚洲欧美在线一区二区 | 亚洲精品免费在线观看 | 欧美日韩一区二区在线 | 亚洲综合首页 | 91社影院在线观看 | 久久se精品一区精品二区 | 久久久久久精 | 性处破╳╳╳高清欧美 | 黄网站涩免费蜜桃网站 | av免费网站| 九九热欧美 | 欧美激情一区二区 | 国产精品久久免费看 | 丁香婷婷久久久综合精品国产 | 精品一区二区三区在线视频 | 精品久久久久久久久久久 | 亚洲第一成人在线视频 | 禁果av一区二区三区 | 亚洲精品视频在线 | 岛国精品| 精品国产一区在线 | 国产美女av在线 | 久久99精品久久久水蜜桃 | 1区2区免费视频 | 美女福利网站 | 亚洲精品电影在线观看 | 不卡一区 | 日韩视频在线视频 | 国产在线精品一区二区 | 亚洲乱码国产乱码精品精98午夜 | 天天躁日日躁狠狠躁av麻豆 | 亚洲精品一区中文字幕乱码 | 精品欧美日韩 | 综合国产 | 91资源总站 | 一级人爱视频 | 超碰在线人人 | av网站观看 | 欧美第一页 | 国产日产精品一区二区三区四区 | 九九色综合 | 欧美中文字幕在线观看 | 美女一区二区三区在线观看 | 欧美黑人一区 | 日韩在线视频一区 | 日韩综合网 | 伊人免费视频 | 精品视频在线观看一区二区 | 美女视频一区二区三区 | 午夜精品久久久久久久久 | 日韩一区二区三区在线视频 | 人人干天天操 | 久久99精品国产.久久久久 | 91高清视频在线观看 | 激情综合久久 | 亚洲精品成人 | 欧美日韩在线视频一区 | 国产精品亚洲综合 | 久久精品欧美一区二区三区不卡 | 国产精选一区二区 | 亚洲欧美日韩精品久久奇米色影视 | 在线精品一区 | 日韩不卡av | 国产精品久久久精品 | 日本一区二区不卡 | 天天爽夜夜爽夜夜爽精品视频 | 久久国产精品视频观看 | 日本黄色免费大片 | 99热在线免费观看 | 国产免费久久 | 色橹橹欧美在线观看视频高清 | 欧美激情国产日韩精品一区18 | 偷拍呻吟高潮91 | 欧美一区永久视频免费观看 | 中文字幕一区二区三区不卡 | 国产精品久久久久久久久免费丝袜 | 亚洲第一福利视频 | 久久国产视频精品 | 久久这里只有精品首页 | 欧美精品成人 | 精品一二区 | 久久9999久久 | 在线日本中文字幕 | 国产精品久久一区二区三区 | 成人在线免费 | 久久久久久一区二区 | 爱爱日韩 | 国产精品亚洲视频 | 久久久精品免费观看 | 91.成人天堂一区 | 欧美中文字幕在线观看 | 欧美黄色网 | 亚洲男人天堂网 | 99久久免费观看 | 欧美xxxx黑人又粗又长 | 国产三级视频 | 一区二区福利 | 日韩欧美二区 | 中文字幕在线观看不卡视频 | 国产综合精品一区二区三区 | 精品久| 国产精品色综合 | 波多野结衣福利电影 | 最新中文字幕视频 | 三级视频在线 | 日韩成人在线视频 | 日本一级毛片视频 | 色在线看| 精品国产一区二区在线 | 蜜桃av人人夜夜澡人人爽 | 精品国产一区二区三区性色 | 国产综合亚洲精品一区二 | 国产精品成av人在线视午夜片 | 日韩和的一区二区 | 亚洲夜幕久久日韩精品一区 | 91在线观看视频 | 亚洲高清视频在线 | 久久999| 99精品久久久久 | 国产精品三级视频 | 天天久久 | 午夜欧美| 在线观看av国产一区二区 | 热久久国产 | 中文字幕一级 | 红桃成人少妇网站 | 精品久久精品 | 久久精品手机视频 | 国产精品99久久免费观看 | 欧美日在线 | www.久久| 一区二区三区免费 | 欧美激情一区二区三区四区 | 一区二区三区四区免费看 | 国产女人免费看a级丨片 | 69久久久| 精品一区二区三区四区视频 | 日日日操| 国产一区二区三区高清 | 久久久高清 | 久久女人 | 国产精品美女久久久久久久久久久 | 黄色a级网站 | 精品亚洲永久免费精品 | 亚洲怡红院在线观看 | 欧美精品一区久久 | 亚洲 自拍 另类 欧美 丝袜 | 午夜男人天堂 | 亚洲精选久久 | 免费观看黄色大片 | 91无吗 | 天天天天干| 成人精品久久久 | 男人天堂视频网 | 国产精品第一区第27页 | 欧美成在线观看 | 久久久久久亚洲精品视频 | 99热精品在线 | 婷婷综合 | 亚洲国产精品一区二区久久 | 在线播放亚洲 | 在线视频 中文字幕 | 久久99精品久久久久久园产越南 | 成年视频在线观看福利资源 | 欧美三级电影在线播放 | 美女一级黄 | 国产一区二区三区在线 | 国产黄色大片免费看 | 第一色视频 | 人人做人人澡人人爽欧美 | 国产精品揄拍一区二区久久国内亚洲精 | 91操碰| 久久成人综合网 | www.麻豆视频| 日韩欧美中文字幕在线视频 | 九九色综合| 91高清视频在线观看 | 亚洲专区欧美 | 91精品国产综合久久久久久 | 99热国产精品 | 伊人色综合久久久天天蜜桃 | 一区不卡| 成人在线免费观看 | 国产小视频在线观看 | 日韩在线视频观看 | 99re视频在线播放 | 亚洲综合一区二区 | 日韩精品av一区二区三区 | 国产欧美精品一区二区三区 | 日本a在线 | 一区二区三区国产免费 | 精品国模一区二区三区欧美 | 久久久久久久久一区 | 91国产精品 | 久久r免费视频 | 精品成人av | 天天干网| 中文字幕一区二区三区乱码图片 | 日韩欧美~中文字幕 | 成a人片在线观看 | 久久久久国产精品免费免费搜索 | 日本狠狠操 | 99精品在线| 国产一区二区av在线 | 亚洲高清免费视频 | 一区综合| 在线观看第一页 | 欧美一区二区视频 | 午夜精品一区二区三区在线观看 | 手机看片169 | 香蕉婷婷 | 国产成人精品综合 | 91久久久久久 | 欧洲妇女成人淫片aaa视频 | 涩涩视频网站在线观看 | 国产高清精品一区二区三区 | 亚洲精品久久久久久下一站 | 成人av免费观看 | 色综合色综合 | 欧美精品 在线观看 | 亚洲综合激情网 | 91麻豆精品国产91久久久更新资源速度超快 | 手机看片亚洲 | 国内久久精品 | 99精品欧美一区二区三区 | 国产精品毛片 | 国语精品久久 | 国产日韩欧美激情 | 日韩在线观看视频一区 | 久久久久久一区二区 | 百性阁综合另类 | 免费观看在线午夜影视 | 在线播放国产精品 | 亚洲国产精品va在线看黑人 | 国产免费久久 | 成人一区二区三区在线观看 | 久久精品这里只有精品 | 午夜小电影| 99在线观看 | 国产性猛交xxxx免费看久久 | 亚洲精品二三区 | 综合久久亚洲 | 久久精品一 | 欧美一区二区激情三区 | 欧美久久精品一级c片 | 中出片| 精品香蕉一区二区三区 | 成人在线视频一区 | 小泽玛丽娅 | www.国产精 | 一级篇| 黄色二区 | 婷婷在线视频 | 亚洲视频综合 | 色噜噜一区二区 | 99国产视频| 亚洲热av| 亚洲精品视频免费看 | 91电影在线 | 精品国产髙清在线看国产毛片 | 免费成人在线观看视频 | 成人精品视频 | www国产在线观看 | 欧美成年黄网站色视频 | 黄色毛片看看 | 青娱乐99| 精品国产欧美一区二区三区不卡 | 成人水多啪啪片 | 成人精品在线观看 | 99爱免费观看国语 | 久久久久久久成人 | 成人一区二区av | 亚洲精品电影网在线观看 | 夜夜操天天干, | 成人午夜免费视频 | 夸克满天星在线观看 | 国产精品久久久久无码av | 91精品综合久久久久久五月天 | 性视频黄色 | 国产一级免费 | 看av网站| 精品国产不卡一区二区三区 | 亚洲精品不卡 | 我爱操 | 色爱综合网 | 欧美在线激情 | av中文字幕在线观看 | 丁香五月亚洲综合在线 | 精品一区av| av在线网址观看 | 欧美福利在线 | 农村妇女毛片精品久久久 | 久久九九这里只有精品 | 色国产精品 | 国产日韩成人 | 中文字幕在线免费 | 欧美日韩中文字幕 | 日韩三区在线 | 亚洲欧美日韩在线一区二区三区 | 狠狠撸在线视频 | 成人精品视频 | 国偷自产av一区二区三区 | 色综合久久久久 | 一区二区三区免费在线观看 | 九九免费观看全部免费视频 | 日韩国产一区二区三区 | 欧美久久一级特黄毛片 | 一级毛片在线看aaaa | 亚洲精品一区在线观看 | 国产精品一区一区三区 | 国产成人久久 | 久久福利 | 国产精品高潮呻吟久久av野狼 | 97av在线视频| 中文字幕日韩在线 | 91欧美激情一区二区三区成人 | 黄色小视频在线观看 | 人人玩人人添人人澡97 | 性色爽爱 | 欧美一级黄色网 | 久久九九 | 国产97色在线 | 亚洲 | 国产精品视频入口 | 日韩av电影观看 | 欧美一区二区三区精品 | 日韩视频免费在线观看 | 精品av| 欧美激情综合五月色丁香小说 | 成人在线播放网站 | 久久99精品久久久久久园产越南 | 日韩一区二区在线电影 | 天天操天天干天天爽 | av黄色在线看 | 国产香蕉97碰碰久久人人九色 | 在线观看a视频 | 天天插天天干 | 国产精品无码永久免费888 | 国产一级高清视频 | 99热精品免费 | 日本在线免费 | 午夜在线电影 | 69日影院 | 欧美日韩三区 | 91久久国产综合久久 | 国产免费一区二区三区 | 伊人亚洲| 狠狠狠色丁香婷婷综合久久五月 | 中文字幕亚洲欧美日韩在线不卡 | 午夜精品久久久久久久久久久久 | 国产精品成人观看视频国产奇米 | 欧美黄视频 | 91免费网 | 国产精品久久嫩一区二区免费 | 精品日韩一区二区 | 亚洲综合精品视频 | 在线成人亚洲 | 日韩精品中文字幕在线播放 | 午夜午夜精品一区二区三区文 | 成人免费毛片aaaaaa片 | 亚洲精品久久久久久久久久久 | 国产精品日韩欧美 | 精品免费久久久久久久苍 | 精品国产乱码一区二区三区 | 2018国产大陆天天弄 | 国产精品久久久久久久一区探花 | 色网在线观看 | 国产欧美日韩综合精品一区二区 | 日韩欧美国产一区二区 | 日韩视频在线观看视频 | 99视频在线 | 99久久免费观看 | 爱爱视频在线观看 | 日本在线免费看 | 国产高潮在线观看 | 亚洲一级在线观看 | av一区二区三区四区 | 国产精品国产三级国产aⅴ无密码 | 精品国产乱码久久久久久1区2区 | 欧美精品成人一区二区三区四区 | 色综合天天综合网国产成人网 | 欧美大片一区 | 电影91久久久 | 亚洲小视频 | 日韩精品一二三 | 欧美日韩一区二区中文字幕 | 97视频人人澡人人爽 | 欧美第一视频 | 在线免费观看成年人视频 | 精品国产不卡一区二区三区 | 亚洲精品乱码久久久久久麻豆不卡 | 91电影在线 | 激情久久av一区av二区av三区 | 国产成人一区二区三区影院在线 | 日韩在线视频免费 | 日韩五月 | 狠狠久久综合 | 免费在线一区二区三区 | 欧美激情高清 | 红桃av一区二区 | 骚视频在线观看 | 国产在线精品一区二区三区 | 久久成人综合网 | 国产精品久久久久久久久久久久久 | 狠狠爱天天操 | 婷婷色国产偷v国产偷v小说 | 日本精品一区二区三区在线观看 | 综合久久综合久久 | 亚洲永久免费视频 | 夜夜草天天干 | 国产精品第一国产精品 | 自拍偷拍第一页 | 日韩成人在线观看 | 91啦| 久久久成人av | 国产在线在线 | 精品日韩一区二区三区 | www.99精品 | 日韩不卡中文字幕 | 欧美国产日韩一区 | 欧美一区二区三区免费电影 | 久久ri资源网 | 午夜欧美精品久久久久 | 欧美精品免费在线观看 | 可以免费看黄视频的网站 | 色综久久 | 日韩视频在线一区二区 | 国产一区二区精品久久岳 | 精品久久一区 | www在线观看国产 | 在线观看日韩精品 | 亚洲午夜在线 | av影音 | 99久久精品免费看国产一区二区三区 | 国产一级一级特黄女人精品毛片 | 精品亚洲视频在线 | 国产91色| 日韩福利 | 国产一区二区久久 | 成人午夜激情 | 成人免费在线视频播放 | 激情一区二区三区 | 四虎永久网址 | 欧美一区二区激情三区 | 国产精选一区二区 | 超级碰在线视频 | 日韩欧美一区二区在线 | 久久精品在线 | 久久久久久国产精品 | 亚洲精品自在在线观看 | 国产成人亚洲综合 | 亚洲综合无码一区二区 | 日本妇乱大交xxxxx | 国产亚洲成av人片在线观看桃 | 亚洲久视频 | 日韩精品 | 亚洲精品国产精品国自产 | 亚洲乱码一区二区三区在线观看 | 国产一区免费在线观看 | 欧美国产精品一区 | 国产色| 久久久久久久久国产 | 国产美女在线观看 | 密室大逃脱第六季大神版在线观看 | h视频免费在线 | 精品国产一级毛片 | 亚洲久久久 | 国产91成人在在线播放 | 日韩欧美综合 | 天天操网 | 欧美aaa一级片 | 男人的天堂久久 | 欧美日韩视频第一页 | 一区综合| 中文字幕一区在线观看视频 | 国产成人av在线 | 国产精品1区2区 | 成人免费视频网站 | 91中文字幕在线观看 | 欧美日韩国产一区二区在线观看 | a视频在线| 久久久影院 | 亚洲伊人久久网 | 免费观看电视在线高清视频 | 亚洲免费在线播放 | 国产精彩视频 | 免费国产黄色大片 | 在线视频亚洲 | 伊人福利视频 | 91精品午夜| 99re6在线视频精品免费 | 91精品国产一区二区三区四区在线 | 一本大道综合伊人精品热热 | 午夜精品久久久久久久白皮肤 | 久久久国产视频 | 亚洲成人免费电影 | a久久免费视频 | 精品国产一区二区三区不卡蜜臂 | 国产日产精品一区二区三区四区 | 久久这里只有精品首页 |