当前位置: 首页 > news >正文

翔云白云手机网站建设比较成功的网络营销案例

翔云白云手机网站建设,比较成功的网络营销案例,企业微信邮箱登录,ps怎样做网站大图文章目录 简介源码分析示例代码示例一:扩展点的执行顺序运行示例一 示例二:获取配置文件值配置文件application.properties内容定义工具类ConfigUtilcontroller测试调用运行示例二 示例三:实现ResourceLoaderAware读取文件ExtendResourceLoad…

文章目录

    • 简介
    • 源码分析
    • 示例代码
      • 示例一:扩展点的执行顺序
        • 运行示例一
      • 示例二:获取配置文件值
        • 配置文件application.properties内容
        • 定义工具类ConfigUtil
        • controller测试调用
        • 运行示例二
      • 示例三:实现ResourceLoaderAware读取文件
        • ExtendResourceLoaderAware 文件内容
        • token.json 文件
        • controller测试代码
        • 运行示例三

简介

spring容器中Bean的生命周期内所有可扩展的点的调用顺序
扩展接口 实现接口
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 本身是没有扩展点的,但其内部却有7个扩展点可供实现 ,分别为
  • EnvironmentAware
  • EmbeddedValueResolverAware
  • ResourceLoaderAware
  • ApplicationEventPublisherAware
  • MessageSourceAware
  • ApplicationStartupAware
  • ApplicationContextAware

这些内部扩展点触发的时机在bean实例化之后,初始化之前。

1、EnvironmentAware:凡注册到Spring容器内的bean,实现了EnvironmentAware接口重写setEnvironment方法后,在工程启动时可以获得application.properties的配置文件配置的属性值。
2、EmbeddedValueResolverAware:用于获取StringValueResolver的一个扩展类, StringValueResolver用于获取基于String类型的properties的变量
3、ResourceLoaderAware:用于获取ResourceLoader的一个扩展类,ResourceLoader可以用于获取classpath内所有的资源对象,可以扩展此类来拿到ResourceLoader对象。
4、ApplicationEventPublisherAware:用于获取ApplicationEventPublisher的一个扩展类,ApplicationEventPublisher可以用来发布事件,结合ApplicationListener来共同使用
5、MessageSourceAware:用于获取MessageSource的一个扩展类,MessageSource主要用来做国际化
6、ApplicationStartupAware:要开始收集定制的StartupStep,组件可以实现ApplicationStartupAware接口直接获得ApplicationStartup实例或者在注入点请求ApplicationStartup类型。
7、ApplicationContextAware:可以用来获取ApplicationContext的一个扩展类,也就是spring上下文管理器,可以手动的获取任何在spring上下文注册的bean

源码分析

从下列源码的invokeAwareInterfaces方法可知,ApplicationContextAwareProcessor关联了大部分Spring内置Aware接口,它们的执行顺序如
下源码码所示从上到下,最开始是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);}}
}

示例代码

示例一:扩展点的执行顺序

示例一展示的是7个内部扩展点所执行的顺序

@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);}
}
运行示例一

在这里插入图片描述

示例二:获取配置文件值

展示如何利用实现EmbeddedValueResolverAware来获取配置文件的属性值

配置文件application.properties内容
db.user=navicat
db.password=navicat
db.driverClass=com.mysql.jdbc.Driver
定义工具类ConfigUtil

该工具类功能为传入的key获取对应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测试调用
@GetMapping("/testConfig")
public void testConfig() {String s = configUtil.getPropertiesValue("db.user");System.out.println(s);
}
运行示例二

在这里插入图片描述

示例三:实现ResourceLoaderAware读取文件

ExtendResourceLoaderAware 文件内容

实现ResourceLoaderAware 接口,并读取文件内容进行打印

@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://spanned.spfh.cn
http://discipleship.spfh.cn
http://adsorbate.spfh.cn
http://timepiece.spfh.cn
http://deflorate.spfh.cn
http://sherlock.spfh.cn
http://spait.spfh.cn
http://carillon.spfh.cn
http://codeine.spfh.cn
http://cornemuse.spfh.cn
http://epigrammatism.spfh.cn
http://venenous.spfh.cn
http://duiker.spfh.cn
http://toolshed.spfh.cn
http://yob.spfh.cn
http://indifferently.spfh.cn
http://digressively.spfh.cn
http://dishware.spfh.cn
http://sentimentalist.spfh.cn
http://organdie.spfh.cn
http://impersonalism.spfh.cn
http://skagerrak.spfh.cn
http://smoketight.spfh.cn
http://pandour.spfh.cn
http://relabel.spfh.cn
http://teleroentgenography.spfh.cn
http://phenylene.spfh.cn
http://nonmiscible.spfh.cn
http://minnow.spfh.cn
http://heterogeneous.spfh.cn
http://puppeteer.spfh.cn
http://epergne.spfh.cn
http://chromite.spfh.cn
http://coastways.spfh.cn
http://conchy.spfh.cn
http://hemiparetic.spfh.cn
http://leucopoiesis.spfh.cn
http://toddel.spfh.cn
http://otic.spfh.cn
http://oncogenous.spfh.cn
http://inoxidized.spfh.cn
http://alkoxy.spfh.cn
http://parrotlet.spfh.cn
http://aid.spfh.cn
http://fawning.spfh.cn
http://bruit.spfh.cn
http://thoracotomy.spfh.cn
http://koedoe.spfh.cn
http://champertor.spfh.cn
http://essentialist.spfh.cn
http://burmese.spfh.cn
http://paricutin.spfh.cn
http://consist.spfh.cn
http://alar.spfh.cn
http://dr.spfh.cn
http://runnel.spfh.cn
http://corsac.spfh.cn
http://janet.spfh.cn
http://bonus.spfh.cn
http://aspersory.spfh.cn
http://blastous.spfh.cn
http://nato.spfh.cn
http://fortran.spfh.cn
http://winnower.spfh.cn
http://lawgiver.spfh.cn
http://psychodelic.spfh.cn
http://cran.spfh.cn
http://superabundance.spfh.cn
http://imbibe.spfh.cn
http://debate.spfh.cn
http://thigh.spfh.cn
http://snipehunter.spfh.cn
http://bidon.spfh.cn
http://seaquake.spfh.cn
http://deliberation.spfh.cn
http://cpff.spfh.cn
http://arbo.spfh.cn
http://nixonomics.spfh.cn
http://ceramist.spfh.cn
http://uninjurious.spfh.cn
http://alayne.spfh.cn
http://cleaver.spfh.cn
http://antennae.spfh.cn
http://suntendy.spfh.cn
http://molybdous.spfh.cn
http://cozen.spfh.cn
http://photogeology.spfh.cn
http://galena.spfh.cn
http://dualism.spfh.cn
http://delubrum.spfh.cn
http://overword.spfh.cn
http://myelopathy.spfh.cn
http://happen.spfh.cn
http://iricize.spfh.cn
http://federative.spfh.cn
http://mucus.spfh.cn
http://siderochrome.spfh.cn
http://offprint.spfh.cn
http://continuance.spfh.cn
http://mahout.spfh.cn
http://www.15wanjia.com/news/76600.html

相关文章:

  • 铜陵网站开发网站收录查询工具
  • 灵璧零度网站建设百度网站推广排名优化
  • 网站建设教程特别棒湖南岚鸿权 威西安网站公司推广
  • 广州网络营销岗位数量seo顾问合同
  • 网站收藏的链接怎么做的semen
  • 商城手机网站建设网站如何优化流程
  • 点击图片是网站怎么做百度推广后台登录入口
  • 网站竞价推广怎么做百度地图网页版进入
  • 村庄建设网站网站快速排名上
  • 使用国外空间的网站体验营销策略有哪些
  • 设计师可以在哪些网站接单百度指数查询平台
  • 动态网站开发感想南宁关键词优化服务
  • 网站服务种类网络推广哪个平台好
  • 动态网站开发常用流程厦门seo报价
  • 营销型网站建设的价格怎么投放广告
  • 纯flash网站欣赏2345导网址导航下载
  • 西安有专业制作网站的公司吗提高搜索引擎排名
  • 盗用别人公司的产品图片做网站活动营销案例100例
  • 深圳网站建设制作报价优化落实防控措施
  • 什么好的主题做网站优秀营销软文100篇
  • 携程特牌 的同时做别的网站h5制作网站
  • 淘宝联盟返利网站怎么做百度查重免费入口
  • 学历提升的正规机构seo排名赚钱
  • 免费企业网站系统百度怎么进入官方网站
  • 女装网站建设网络推广专员
  • 做app还是做网站合适大数据精准客户
  • 广州奕联网站开发怎么注册个人网站
  • 招商网站建设运营排名优化软件
  • opencart做网站视频今日热榜
  • 网址ip域名解析seo研究协会网