中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

wordpress如何上傳超過2m合肥seo網(wǎng)站排名

wordpress如何上傳超過2m,合肥seo網(wǎng)站排名,京東網(wǎng)站的公司全名,企業(yè)網(wǎng)站找誰做文章目錄 簡介源碼分析示例代碼示例一:擴(kuò)展點的執(zhí)行順序運行示例一 示例二:獲取配置文件值配置文件application.properties內(nèi)容定義工具類ConfigUtilcontroller測試調(diào)用運行示例二 示例三:實現(xiàn)ResourceLoaderAware讀取文件ExtendResourceLoad…

文章目錄

    • 簡介
    • 源碼分析
    • 示例代碼
      • 示例一:擴(kuò)展點的執(zhí)行順序
        • 運行示例一
      • 示例二:獲取配置文件值
        • 配置文件application.properties內(nèi)容
        • 定義工具類ConfigUtil
        • controller測試調(diào)用
        • 運行示例二
      • 示例三:實現(xiàn)ResourceLoaderAware讀取文件
        • ExtendResourceLoaderAware 文件內(nèi)容
        • token.json 文件
        • controller測試代碼
        • 運行示例三

簡介

spring容器中Bean的生命周期內(nèi)所有可擴(kuò)展的點的調(diào)用順序
擴(kuò)展接口 實現(xiàn)接口
ApplicationContextlnitializer initialize
AbstractApplicationContext refreshe
BeanDefinitionRegistryPostProcessor postProcessBeanDefinitionRegistry
BeanDefinitionRegistryPostProcessor postProcessBeanFactory
BeanFactoryPostProcessor postProcessBeanFactory
instantiationAwareBeanPostProcessor postProcessBeforelnstantiation
SmartlnstantiationAwareBeanPostProcessor determineCandidateConstructors
MergedBeanDefinitionPostProcessor postProcessMergedBeanDefinition
InstantiationAwareBeanPostProcessor postProcessAfterlnstantiation
SmartInstantiationAwareBeanPostProcessor getEarlyBeanReference
BeanNameAware setBeanName
BeanFactoryAware postProcessPropertyValues
ApplicationContextAwareProcessor invokeAwarelnterfaces
InstantiationAwareBeanPostProcessor postProcessBeforelnstantiation
@PostConstruct
InitializingBean afterPropertiesSet
FactoryBean getobject
SmartlnitializingSingleton afterSingletonslnstantiated
CommandLineRunner run
DisposableBeandestroy
今天要介紹的是ApplicationContextAwareProcessor ,ApplicationContextAwareProcessor 本身是沒有擴(kuò)展點的,但其內(nèi)部卻有7個擴(kuò)展點可供實現(xiàn) ,分別為
  • EnvironmentAware
  • EmbeddedValueResolverAware
  • ResourceLoaderAware
  • ApplicationEventPublisherAware
  • MessageSourceAware
  • ApplicationStartupAware
  • ApplicationContextAware

這些內(nèi)部擴(kuò)展點觸發(fā)的時機(jī)在bean實例化之后,初始化之前。

1、EnvironmentAware:凡注冊到Spring容器內(nèi)的bean,實現(xiàn)了EnvironmentAware接口重寫setEnvironment方法后,在工程啟動時可以獲得application.properties的配置文件配置的屬性值。
2、EmbeddedValueResolverAware:用于獲取StringValueResolver的一個擴(kuò)展類, StringValueResolver用于獲取基于String類型的properties的變量
3、ResourceLoaderAware:用于獲取ResourceLoader的一個擴(kuò)展類,ResourceLoader可以用于獲取classpath內(nèi)所有的資源對象,可以擴(kuò)展此類來拿到ResourceLoader對象。
4、ApplicationEventPublisherAware:用于獲取ApplicationEventPublisher的一個擴(kuò)展類,ApplicationEventPublisher可以用來發(fā)布事件,結(jié)合ApplicationListener來共同使用
5、MessageSourceAware:用于獲取MessageSource的一個擴(kuò)展類,MessageSource主要用來做國際化
6、ApplicationStartupAware:要開始收集定制的StartupStep,組件可以實現(xiàn)ApplicationStartupAware接口直接獲得ApplicationStartup實例或者在注入點請求ApplicationStartup類型。
7、ApplicationContextAware:可以用來獲取ApplicationContext的一個擴(kuò)展類,也就是spring上下文管理器,可以手動的獲取任何在spring上下文注冊的bean

源碼分析

從下列源碼的invokeAwareInterfaces方法可知,ApplicationContextAwareProcessor關(guān)聯(lián)了大部分Spring內(nèi)置Aware接口,它們的執(zhí)行順序如
下源碼碼所示從上到下,最開始是EnvironmentAware,最后是ApplicationContextAware

package org.springframework.context.support;class ApplicationContextAwareProcessor implements BeanPostProcessor {private final ConfigurableApplicationContext applicationContext;private final StringValueResolver embeddedValueResolver;/*** Create a new ApplicationContextAwareProcessor for the given context.*/public ApplicationContextAwareProcessor(ConfigurableApplicationContext applicationContext) {this.applicationContext = applicationContext;this.embeddedValueResolver = new EmbeddedValueResolver(applicationContext.getBeanFactory());}@Override@Nullablepublic Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {if (!(bean instanceof EnvironmentAware || bean instanceof EmbeddedValueResolverAware ||bean instanceof ResourceLoaderAware || bean instanceof ApplicationEventPublisherAware ||bean instanceof MessageSourceAware || bean instanceof ApplicationContextAware ||bean instanceof ApplicationStartupAware)) {return bean;}AccessControlContext acc = null;if (System.getSecurityManager() != null) {acc = this.applicationContext.getBeanFactory().getAccessControlContext();}if (acc != null) {AccessController.doPrivileged((PrivilegedAction<Object>) () -> {invokeAwareInterfaces(bean);return null;}, acc);}else {invokeAwareInterfaces(bean);}return bean;}private void invokeAwareInterfaces(Object bean) {if (bean instanceof EnvironmentAware) {((EnvironmentAware) bean).setEnvironment(this.applicationContext.getEnvironment());}if (bean instanceof EmbeddedValueResolverAware) {((EmbeddedValueResolverAware) bean).setEmbeddedValueResolver(this.embeddedValueResolver);}if (bean instanceof ResourceLoaderAware) {((ResourceLoaderAware) bean).setResourceLoader(this.applicationContext);}if (bean instanceof ApplicationEventPublisherAware) {((ApplicationEventPublisherAware) bean).setApplicationEventPublisher(this.applicationContext);}if (bean instanceof MessageSourceAware) {((MessageSourceAware) bean).setMessageSource(this.applicationContext);}if (bean instanceof ApplicationStartupAware) {((ApplicationStartupAware) bean).setApplicationStartup(this.applicationContext.getApplicationStartup());}if (bean instanceof ApplicationContextAware) {((ApplicationContextAware) bean).setApplicationContext(this.applicationContext);}}
}

示例代碼

示例一:擴(kuò)展點的執(zhí)行順序

示例一展示的是7個內(nèi)部擴(kuò)展點所執(zhí)行的順序

@Slf4j
@Configuration
public class ExtendInvokeAware implements EnvironmentAware, EmbeddedValueResolverAware, ResourceLoaderAware,ApplicationEventPublisherAware, MessageSourceAware, ApplicationStartupAware, ApplicationContextAware, BeanNameAware {@Overridepublic void setApplicationContext(ApplicationContext applicationContext) throws BeansException {log.info("setApplicationContext--Extend--run {}",applicationContext);}@Overridepublic void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {log.info("setApplicationEventPublisher--Extend--run {}",applicationEventPublisher);}@Overridepublic void setApplicationStartup(ApplicationStartup applicationStartup) {log.info("setApplicationStartup--Extend--run {}",applicationStartup);}@Overridepublic void setEmbeddedValueResolver(StringValueResolver resolver) {log.info("setEmbeddedValueResolver--Extend--run {}",resolver);}@Overridepublic void setEnvironment(Environment environment) {log.info("setEnvironment--Extend--run {}",environment);}@Overridepublic void setMessageSource(MessageSource messageSource) {log.info("setMessageSource--Extend--run {}",messageSource);}@Overridepublic void setResourceLoader(ResourceLoader resourceLoader) {log.info("setResourceLoader--Extend--run {}",resourceLoader);}@Overridepublic void setBeanName(String name) {log.info("setBeanName--Extend--run {}",name);}
}
運行示例一

在這里插入圖片描述

示例二:獲取配置文件值

展示如何利用實現(xiàn)EmbeddedValueResolverAware來獲取配置文件的屬性值

配置文件application.properties內(nèi)容
db.user=navicat
db.password=navicat
db.driverClass=com.mysql.jdbc.Driver
定義工具類ConfigUtil

該工具類功能為傳入的key獲取對應(yīng)value

@Component
public class ConfigUtil implements EmbeddedValueResolverAware {private StringValueResolver resolver;@Overridepublic void setEmbeddedValueResolver(StringValueResolver resolver) {this.resolver = resolver;}/*** 獲取屬性,直接傳入屬性名稱即可* @param key* @return*/public String getPropertiesValue(String key) {StringBuilder name = new StringBuilder("${").append(key).append("}");return resolver.resolveStringValue(name.toString());}}
controller測試調(diào)用
@GetMapping("/testConfig")
public void testConfig() {String s = configUtil.getPropertiesValue("db.user");System.out.println(s);
}
運行示例二

在這里插入圖片描述

示例三:實現(xiàn)ResourceLoaderAware讀取文件

ExtendResourceLoaderAware 文件內(nèi)容

實現(xiàn)ResourceLoaderAware 接口,并讀取文件內(nèi)容進(jìn)行打印

@Slf4j
@Configuration
public class ExtendResourceLoaderAware implements ResourceLoaderAware {private ResourceLoader resourceLoader;@Overridepublic void setResourceLoader(ResourceLoader resourceLoader) {this.resourceLoader = resourceLoader;log.info("ApplicationContextAware--Extend--run {}",resourceLoader);}public void showResourceData() throws IOException{//This line will be changed for all versions of other examplesResource banner = resourceLoader.getResource("file:d:/token.json");InputStream in = banner.getInputStream();BufferedReader reader = new BufferedReader(new InputStreamReader(in));while (true) {String line = reader.readLine();if (line == null)break;System.out.println(line);}reader.close();}
}
token.json 文件
{"name":"張三"}
controller測試代碼
@Autowired
ApplicationContext context;@SuppressWarnings("resource")
@GetMapping("/testResource")
public void testResource() throws Exception{ExtendResourceLoaderAware extendResourceLoaderAware = (ExtendResourceLoaderAware) context.getBean("extendResourceLoaderAware");extendResourceLoaderAware.showResourceData();
}
運行示例三

在這里插入圖片描述

http://www.risenshineclean.com/news/34833.html

相關(guān)文章:

  • 公安廳網(wǎng)站 做10道相關(guān)題目2022年小學(xué)生新聞?wù)畻l
  • 河南網(wǎng)站制作線上銷售平臺有哪些
  • 貴州省網(wǎng)站節(jié)約化建設(shè)通知公司網(wǎng)址怎么制作
  • php網(wǎng)站開發(fā)需要什么軟件友情鏈接獲取的途徑有哪些
  • 網(wǎng)站后臺視頻app開發(fā)公司哪家好
  • 有關(guān)做聚合物電池公司的網(wǎng)站什么是網(wǎng)絡(luò)營銷渠道
  • 河南網(wǎng)站推廣網(wǎng)站seo好學(xué)嗎
  • 網(wǎng)站建設(shè)方案市場營銷策劃方案
  • 青島網(wǎng)站制作價格南京百度提升優(yōu)化
  • 蘇州做物流網(wǎng)站電話淘寶店怎么運營和推廣
  • 用ps如何做網(wǎng)站首頁網(wǎng)絡(luò)市場調(diào)研的五個步驟
  • 開花店做網(wǎng)站網(wǎng)絡(luò)營銷大賽策劃書
  • 做網(wǎng)站要公安備案嗎百度網(wǎng)盤app怎么打開鏈接
  • 網(wǎng)站3網(wǎng)合一是怎么做的酒吧營銷用什么軟件找客源
  • 企業(yè)網(wǎng)站建設(shè)怎么做推銷產(chǎn)品的萬能句子
  • 頁面簡潔的網(wǎng)站365優(yōu)化大師軟件下載
  • 遼寧品牌建設(shè)促進(jìn)會 網(wǎng)站網(wǎng)絡(luò)優(yōu)化培訓(xùn)
  • 小程序開發(fā)費用多少錢南寧百度首頁優(yōu)化
  • 用別人的電影網(wǎng)站做公眾號惠城網(wǎng)站設(shè)計
  • 震旦集團(tuán)網(wǎng)站建設(shè)中國數(shù)據(jù)統(tǒng)計網(wǎng)站
  • 網(wǎng)站 設(shè)計 分辨率網(wǎng)頁代碼模板
  • 烏海建設(shè)局網(wǎng)站app開發(fā)需要哪些技術(shù)
  • 白城哪家做網(wǎng)站關(guān)鍵詞優(yōu)化排名
  • 網(wǎng)站項目建設(shè)策劃方案建立一個網(wǎng)站需要花多少錢
  • p2p網(wǎng)站如何做測試工具目前疫情最新情況
  • c 做網(wǎng)站源碼實例seo入門教學(xué)
  • 大連專業(yè)網(wǎng)站建設(shè)東莞谷歌推廣
  • 網(wǎng)站建設(shè)外包合同seo外鏈發(fā)布
  • 做網(wǎng)站需要哪些費用seo排名助手
  • 怎么優(yōu)化網(wǎng)站公司網(wǎng)站設(shè)計報價