欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

springboot如何實現(xiàn)自動裝配源碼解讀

 更新時間:2020年12月10日 10:31:08   作者:碼上代碼  
這篇文章主要介紹了springboot如何實現(xiàn)自動裝配源碼賞析,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下

Spring Boot 自動裝配

最重要的注解@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 {

	@AliasFor(annotation = EnableAutoConfiguration.class)
	Class<?>[] exclude() default {};

	@AliasFor(annotation = EnableAutoConfiguration.class)
	String[] excludeName() default {};

	@AliasFor(annotation = ComponentScan.class, attribute = "basePackages")
	String[] scanBasePackages() default {};

	@AliasFor(annotation = ComponentScan.class, attribute = "basePackageClasses")
	Class<?>[] scanBasePackageClasses() default {};

	@AliasFor(annotation = Configuration.class)
	boolean proxyBeanMethods() default true;

}

EnableAutoConfiguration

是實現(xiàn)自動裝配的核心注解

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@AutoConfigurationPackage
@Import(AutoConfigurationImportSelector.class)
public @interface EnableAutoConfiguration {
  
}

getAutoConfigurationMetadata()

@Override
public void process(AnnotationMetadata annotationMetadata, DeferredImportSelector deferredImportSelector) {
	Assert.state(deferredImportSelector instanceof AutoConfigurationImportSelector,
			() -> String.format("Only %s implementations are supported, got %s",
					AutoConfigurationImportSelector.class.getSimpleName(),
					deferredImportSelector.getClass().getName()));
	AutoConfigurationEntry autoConfigurationEntry = ((AutoConfigurationImportSelector) deferredImportSelector)
			.getAutoConfigurationEntry(
					// 加載配置元數(shù)據(jù)
					getAutoConfigurationMetadata(), annotationMetadata);
	this.autoConfigurationEntries.add(autoConfigurationEntry);
	for (String importClassName : autoConfigurationEntry.getConfigurations()) {
		this.entries.putIfAbsent(importClassName, annotationMetadata);
	}
}


private AutoConfigurationMetadata getAutoConfigurationMetadata() {
	if (this.autoConfigurationMetadata == null) {
		// 加載配置信息
		this.autoConfigurationMetadata = AutoConfigurationMetadataLoader.loadMetadata(this.beanClassLoader);
	}
	return this.autoConfigurationMetadata;
}
static AutoConfigurationMetadata loadMetadata(ClassLoader classLoader, String path) {
	try {

	  // 獲取資源路徑
		Enumeration<URL> urls = (classLoader != null) ? classLoader.getResources(path)
				: ClassLoader.getSystemResources(path);
		Properties properties = new Properties();
		while (urls.hasMoreElements()) {
			properties.putAll(PropertiesLoaderUtils.loadProperties(new UrlResource(urls.nextElement())));
		}
		return loadMetadata(properties);
	}
	catch (IOException ex) {
		throw new IllegalArgumentException("Unable to load @ConditionalOnClass location [" + path + "]", ex);
	}
}

protected static final String PATH = "META-INF/spring-autoconfigure-metadata.properties";

注意: 這個文件在target編譯后的文件夾中
自動裝配

spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories

該文件內(nèi)存有:

Auto Configure

org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration,\
org.springframework.boot.autoconfigure.aop.AopAutoConfiguration,\
org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration,\
org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration,\
org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration,\

EnableConfigurationProperties

@ConfigurationProperties(prefix = "spring.redis")
public class RedisProperties {

	/**
	 * Database index used by the connection factory.
	 */
	private int database = 0;

	/**
	 * Connection URL. Overrides host, port, and password. User is ignored. Example:
	 * redis://user:password@example.com:6379
	 */
	private String url;

	/**
	 * Redis server host.
	 */
	private String host = "localhost";

	/**
	 * Login password of the redis server.
	 */
	private String password;

	/**
	 * Redis server port.
	 */
	private int port = 6379;

	/**
	 * Whether to enable SSL support.
	 */
	private boolean ssl;

	/**
	 * Connection timeout.
	 */
	private Duration timeout;

	/**
	 * Client name to be set on connections with CLIENT SETNAME.
	 */
	private String clientName;	

}

希望通過本篇對于springboot自動裝配的解讀,讓大家對springboot底層有了一個大致了解,只分析了主要方法,希望對大家有幫助

到此這篇關(guān)于springboot如何實現(xiàn)自動裝配源碼賞析的文章就介紹到這了,更多相關(guān)springboot自動裝配內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • jdbc結(jié)合dpcp連接池的封裝實例

    jdbc結(jié)合dpcp連接池的封裝實例

    下面小編就為大家?guī)硪黄猨dbc結(jié)合dpcp連接池的封裝實例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-10-10
  • Java System.currentTimeMillis()時間的單位轉(zhuǎn)換與計算方式案例詳解

    Java System.currentTimeMillis()時間的單位轉(zhuǎn)換與計算方式案例詳解

    這篇文章主要介紹了Java System.currentTimeMillis()時間的單位轉(zhuǎn)換與計算方式案例詳解,本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細內(nèi)容,需要的朋友可以參考下
    2021-08-08
  • java中匿名內(nèi)部類解讀分析

    java中匿名內(nèi)部類解讀分析

    本篇文章介紹了,java中匿名內(nèi)部類解讀分析。需要的朋友參考下
    2013-05-05
  • 詳解java連接mysql數(shù)據(jù)庫的五種方式

    詳解java連接mysql數(shù)據(jù)庫的五種方式

    這篇文章主要介紹了詳解java連接mysql數(shù)據(jù)庫的五種方式,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-11-11
  • 解決使用this.getClass().getResource()獲取文件時遇到的坑

    解決使用this.getClass().getResource()獲取文件時遇到的坑

    這篇文章主要介紹了解決使用this.getClass().getResource()獲取文件時遇到的坑問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-12-12
  • hibernate4快速入門實例詳解

    hibernate4快速入門實例詳解

    Hibernate是一個輕量級的ORMapping框架,本文重點給大家介紹hibernate4 入門實例詳細,需要的朋友參考下吧
    2017-09-09
  • Spring Boot 常用注解大全

    Spring Boot 常用注解大全

    這篇文章主要介紹了Spring Boot 常用注解大全,需要的朋友可以參考下
    2024-02-02
  • Java中request對象常用方法匯總

    Java中request對象常用方法匯總

    這篇文章主要為大家詳細匯總了Java中request對象的常用方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-02-02
  • 深入理解Spring中的Lookup(方法注入)

    深入理解Spring中的Lookup(方法注入)

    “Lookup方法”可以使Spring替換一個bean原有的,獲取其它對象具體的方法,并自動返回在容器中的查找結(jié)果。下面這篇文章主要給大家介紹了關(guān)于Spring中Lookup(方法注入)的相關(guān)資料,需要的朋友可以參考下
    2018-05-05
  • SpringBoot+Shiro+LayUI權(quán)限管理系統(tǒng)項目源碼

    SpringBoot+Shiro+LayUI權(quán)限管理系統(tǒng)項目源碼

    本項目旨在打造一個基于RBAC架構(gòu)模式的通用的、并不復雜但易用的權(quán)限管理系統(tǒng),通過SpringBoot+Shiro+LayUI權(quán)限管理系統(tǒng)項目可以更好的幫助我們掌握springboot知識點,感興趣的朋友一起看看吧
    2021-04-04

最新評論