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

珠海网站建设 超凡科技东莞seoseo关键词排名优化

珠海网站建设 超凡科技,东莞seoseo关键词排名优化,绵阳住房和城乡建设部网站,有个做图片mv的网站56概述 spring.factories 实现是依赖 spring-core 包里的 SpringFactoriesLoader 类#xff0c;这个类实现了检索 META-INF/spring.factories 文件#xff0c;并获取指定接口的配置的功能。 Spring Factories机制提供了一种解耦容器注入的方式#xff0c;帮助外部包这个类实现了检索 META-INF/spring.factories 文件并获取指定接口的配置的功能。 Spring Factories机制提供了一种解耦容器注入的方式帮助外部包独立于spring-boot项目注册Bean到spring boot项目容器中。spring.factories 这种机制实际上是仿照 java 中的 SPI 扩展机制实现的。 Spring Factories机制原理 核心类SpringFactoriesLoader 从上文可知Spring Factories机制通过META-INF/spring.factories文件获取相关的实现类的配置信息而SpringFactoriesLoader的功能就是读取META-INF/spring.factories并加载配置中的类。SpringFactoriesLoader主要有两个方法loadFactories和loadFactoryNames。 loadFactoryNames 用于按接口获取Spring Factories文件中的实现类的全称其方法定义如下所示其中参数factoryType指定了需要获取哪个接口的实现类classLoader用于读取配置文件资源。 public static ListString loadFactoryNames(Class? factoryType, Nullable ClassLoader classLoader) loadFactories 用于按接口获取Spring Factories文件中的实现类的实例其方法定义如下所示其中参数factoryType指定了需要获取哪个接口的实现类classLoader用于读取配置文件资源和加载类。 public static T ListT loadFactories(ClassT factoryType, Nullable ClassLoader classLoader) 用法及配置 spring.factories 文件必须放在 resources 目录下的 META-INF 的目录下否则不会生效。如果一个接口希望配置多个实现类可以用,分割。 BootstrapConfiguration 该配置项用于自动引入配置源类似于spring-cloud的bootstrap和nacos的配置通过指定的方式加载我们自定义的配置项信息。该配置项配置的类必须是实现了PropertySourceLocator接口的类。 org.springframework.cloud.bootstrap.BootstrapConfiguration\ xxxxxx.configure.config.ApplicationConfigure public class ApplicationConfigure {BeanConditionalOnMissingBean({CoreConfigPropertySourceLocator.class})public CoreConfigPropertySourceLocator configLocalPropertySourceLocator() {return new CoreConfigPropertySourceLocator();} }public class CoreConfigPropertySourceLocator implements PropertySourceLocator { ..... } ApplicationContextInitializer 该配置项用来配置实现了 ApplicationContextInitializer 接口的类这些类用来实现上下文初始化 org.springframework.context.ApplicationContextInitializer\ xxxxxx.config.TestApplicationContextInitializer public class TestApplicationContextInitializer implements ApplicationContextInitializerConfigurableApplicationContext {Overridepublic void initialize(ConfigurableApplicationContext applicationContext) {System.out.println(TestApplicationContextInitializer.initialize() applicationContext);}} ApplicationListener 配置应用程序监听器该监听器必须实现 ApplicationListener 接口。它可以用来监听 ApplicationEvent 事件。 org.springframework.context.ApplicationListener\ xxxxxxx.factories.listener.TestApplicationListener Slf4j public class TestApplicationListener implements ApplicationListenerTestMessageEvent {Overridepublic void onApplicationEvent(EmailMessageEvent event) {log.info(模拟消息事件... );log.info(TestApplicationListener 接受到的消息{}, event.getContent());} } AutoConfigurationImportListener 该配置项用来配置自动配置导入监听器监听器必须实现 AutoConfigurationImportListener  接口。该监听器可以监听 AutoConfigurationImportEvent 事件。 org.springframework.boot.autoconfigure.AutoConfigurationImportListener\ xxxx.config.TestAutoConfigurationImportListener public class TestAutoConfigurationImportListener implements AutoConfigurationImportListener {Overridepublic void onAutoConfigurationImportEvent(AutoConfigurationImportEvent event) {System.out.println(TestAutoConfigurationImportListener.onAutoConfigurationImportEvent() event);} } AutoConfigurationImportFilter 配置自动配置导入过滤器过滤器必须实现 AutoConfigurationImportFilter 接口。该过滤器用来过滤那些自动配置类可用。 org.springframework.boot.autoconfigure.AutoConfigurationImportFilter\ xxxxxx.config.TestConfigurationCondition public class TestConfigurationCondition implements AutoConfigurationImportFilter {Overridepublic boolean[] match(String[] autoConfigurationClasses, AutoConfigurationMetadata autoConfigurationMetadata) {System.out.println(TestConfigurationCondition.match() autoConfigurationClasses  Arrays.toString(autoConfigurationClasses) , autoConfigurationMetadata autoConfigurationMetadata);return new boolean[0];} } EnableAutoConfiguration 配置自动配置类。这些配置类需要添加 Configuration 注解,可用于注册bean。 org.springframework.boot.autoconfigure.EnableAutoConfiguration\ xxxxx.config.TestConfiguration Configuration public class MyConfiguration {public MyConfiguration() {System.out.println(MyConfiguration());}Beanpublic Testbean testbean(){return new Testbean()}//注册过滤器Beanpublic TestFilter testFilter(){return new TestFilter()}} FailureAnalyzer 配置自定的错误分析类该分析器需要实现 FailureAnalyzer 接口。 org.springframework.boot.diagnostics.FailureAnalyzer\ xxxxx.config.TestFailureAnalyzer /*** 自定义错误分析器*/ public class TestFailureAnalyzer implements FailureAnalyzer {Overridepublic FailureAnalysis analyze(Throwable failure) {System.out.println(TestFailureAnalyzer.analyze() failure failure);return new FailureAnalysis(TestFailureAnalyzer execute, test spring.factories, failure);}}TemplateAvailabilityProvider 配置模板的可用性提供者提供者需要实现 TemplateAvailabilityProvider 接口。 org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider\ xxxxx.config.TestTemplateAvailabilityProvider /*** 验证指定的模板是否支持*/ public class TestTemplateAvailabilityProvider implements TemplateAvailabilityProvider {Overridepublic boolean isTemplateAvailable(String view, Environment environment, ClassLoader classLoader, ResourceLoader resourceLoader) {System.out.println(TestTemplateAvailabilityProvider.isTemplateAvailable() view view , environment environment , classLoader classLoader resourceLoader resourceLoader);return false;}} 自定义Spring Factories机制 首先我们需要先定义两个模块第一个模块A用于定义interface和获取interface的实现类。 代码如下 package com.zhong.spring.demo.demo_7_springfactories;public interface DemoService {void printName(); }package com.zhong.spring.demo.demo_7_springfactories;import lombok.extern.slf4j.Slf4j; import org.springframework.core.io.support.SpringFactoriesLoader; import org.springframework.stereotype.Service;import javax.annotation.PostConstruct; import java.util.List;Slf4j Service public class DemoServiceFactory {PostConstructpublic void printService(){ListString serviceNames SpringFactoriesLoader.loadFactoryNames(DemoService.class,null);for (String serviceName:serviceNames){log.info(name: serviceName);}ListDemoService services SpringFactoriesLoader.loadFactories(DemoService.class,null);for (DemoService demoService:services){demoService.printName();}} }另一个模块B引入A模块并实现DemoService类。并且配置spring.factories 代码如下 package com.zhong.spring.usuldemo.impl;import com.zhong.spring.demo.demo_7_springfactories.DemoService; import lombok.extern.slf4j.Slf4j;Slf4j public class DemoServiceImpl1 implements DemoService {Overridepublic void printName() {log.info(-----------DemoServiceImpl2------------);} }import com.zhong.spring.demo.demo_7_springfactories.DemoService; import lombok.extern.slf4j.Slf4j;Slf4j public class DemoServiceImpl2 implements DemoService {Overridepublic void printName() {log.info(-----------DemoServiceImpl2------------);} } spring.factory配置如下 com.zhong.spring.demo.demo_7_springfactories.DemoService\     com.zhong.spring.usuldemo.impl.DemoServiceImpl1,\     com.zhong.spring.usuldemo.impl.DemoServiceImpl2 启动模块B 得到以下日志;
http://www.w-s-a.com/news/572998/

相关文章:

  • 郑州市建设投资集团公司网站深圳企业网站建设推荐公司
  • 天津个人网站备案查询dz网站恢复数据库
  • 关于网站建设的期刊文献宣传片文案
  • 物业网站模板下载wordpress+菜单大小
  • 网站建设案例教程视频空间刷赞网站推广
  • 网站建设借鉴做外贸球衣用什么网站
  • 网站建设的前途微信公众号制作网站
  • 做网站之前要安装什么网站改进建议有哪些
  • 网站建设+管理系统开发山东专业网站建设公司
  • 基础微网站开发咨询中国印花图案设计网站
  • 找最新游戏做视频网站天津市招标投标公共服务平台
  • 电影订票网站怎么做注册地址出租多少钱
  • 做网站的规划和设想怎样做能让招聘网站记住密码
  • 建站知乎网站公告建设方案
  • 济南市住房和城乡建设局官方网站淮阳住房和城乡建设网站
  • 网站的设计特点有哪些seo推广要多少钱
  • wordpress开通多站点好处软件开发外包公司的设计一般多少钱
  • 为什么我的网站做不起来微信网页版登录手机版下载
  • 苏州市建设职业中心网站北京网站优化方法
  • 于飞网站开发溧阳 招网站开发
  • 网站中的宣传册翻页动画怎么做长沙有哪些网络平台公司
  • 如何做视频门户网站网站建设模板ppt
  • 青岛黄岛区网站开发百度云盘登录入口
  • 建设银行甘肃省行网站房地产市场调研报告
  • js 网站制作合肥公司网站建设
  • 最好建网站系统的软件wordpress调用模版
  • 个人网站备案地址阿里云增加网站
  • 自己做网站要办手续吗重庆短视频制作公司排名
  • 哪个全球购网站做的好汉中门户网官网
  • 网站建设有哪几种wordpress 项目选项