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

南阳网站建设哪家好如何给公司做网络推广

南阳网站建设哪家好,如何给公司做网络推广,郑州seo网站推广,福州网站建设推广服务在Spring框架中PropertySource注解是非常常用的一个注解#xff0c;其主要作用是将外部化配置解析成key-value键值对存入Spring容器的Environment环境中#xff0c;以便在Spring应用中可以通过Value或者占位符${key}的形式来使用这些配置。 使用案列 // Propert…在Spring框架中PropertySource注解是非常常用的一个注解其主要作用是将外部化配置解析成key-value键值对存入Spring容器的Environment环境中以便在Spring应用中可以通过Value或者占位符${key}的形式来使用这些配置。 使用案列 // PropertySource需要和Configuration配个使用 // PropertySource加载的配置文件时需要注意加载的顺序后面加载的配置会覆盖前面加载的配置 // PropertySource支持重复注解 // value值不仅支持classpath表达式还支持任意合法的URI表达式 Configuration PropertySource(value classpath:/my.properties,encoding UTF8) PropertySource(value classpath:/my2.properties,encoding UTF8,ignoreResourceNotFound true) public static class PropertyConfig { }Component public class App {Value(${key1:default-val})private String value;Value(${key2:default-val2})private String value2; }下面是配置文件my.properties和my2.properties的具体内容。 # my.properties key1自由之路# my2.properties key1程序员 key2自由之路Spring容器启动时会将my.properties和my2.properties的内容加载到Environment中并在App类的依赖注入环节将key1和key2的值注入到对应的属性。 自定义PropertySource工厂 阅读PropertySource的源代码我们发现还有一个factory属性。从这个属性的字面意思看我们不难猜测出这个属性设置的是用于产生PropertySource的工厂。 Target(ElementType.TYPE) Retention(RetentionPolicy.RUNTIME) Documented Repeatable(PropertySources.class) public interface PropertySource {String name() default ;String[] value();boolean ignoreResourceNotFound() default false;String encoding() default ;Class? extends PropertySourceFactory factory() default PropertySourceFactory.class;}要深入理解PropertySourceFactory我们先要知道以下的背景知识。 在Spring中配置的来源有很多。Spring将配置来源统一抽象成 PropertySource 这个抽象类Spring中内建的常用的 PropertySource 有以下这些 MapPropertySource CommandLinePropertySource PropertiesPropertySource SystemEnvironmentPropertySource ResourcePropertySource ResourcePropertySource这个类将一系列配置来源统一成ResourcePropertySource可以说是对 PropertySource 的进一步封装。 PropertySourceFactory 接口用于产生PropertySource。Spring中PropertySourceFactory 默认的实现是DefaultPropertySourceFactory用于生产 ResourcePropertySource。 经过上面的介绍我们知道如果没有配置PropertySource的factory属性的话默认的PropertySourceFactory使用的就是DefaultPropertySourceFactory。当然我们也可以自定义PropertySourceFactory用于“生产”我们自定义的PropertySource。下面就演示一个将yaml文件解析成MapPropertySource的使用案列。 /*** Spring中内置的解析yaml的处理器* YamlProcessor* - YamlMapFactoryBean -- 解析成Map* - YamlPropertiesFactoryBean -- 解析成Properties*/ public class YamlMapSourceFactory implements PropertySourceFactory {Overridepublic PropertySource? createPropertySource(String name, EncodedResource resource) throws IOException {YamlMapFactoryBean yamlMapFactoryBean new YamlMapFactoryBean();yamlMapFactoryBean.setResources(resource.getResource());MapString, Object map yamlMapFactoryBean.getObject();return new MapPropertySource(name, map);} }// 加了factory属性必须加name属性 // 有了factory机制我们可以做很多自定一的扩展比如配置可以从远程来 PropertySource(name my.yaml,value classpath:/my.yaml,encoding UTF8,factory YamlMapSourceFactory.class) public static class PropertyConfig { }原理简析 到这边我们对PropertySource已经有了一个感性的认识知道了其主要作用是将各种类型的外部化配置文件以key-value的形式加载到Spring的Environment中。这个部分我们从源码的角度来分析下Spring是怎么处理PropertySource这个注解的。分析源码可以加深我们对PropertySource的认识看源码不是目的是为了加深理解学习Spring的设计思想。 PropertySource注解的处理是在ConfigurationClassPostProcessor中进行触发的。最终会调用到ConfigurationClassParser的processPropertySource方法。 // ConfigurationClassParser#processPropertySource private void processPropertySource(AnnotationAttributes propertySource) throws IOException {String name propertySource.getString(name);if (!StringUtils.hasLength(name)) {name null;}String encoding propertySource.getString(encoding);if (!StringUtils.hasLength(encoding)) {encoding null;}String[] locations propertySource.getStringArray(value);Assert.isTrue(locations.length 0, At least one PropertySource(value) location is required);boolean ignoreResourceNotFound propertySource.getBoolean(ignoreResourceNotFound);Class? extends PropertySourceFactory factoryClass propertySource.getClass(factory);// 如果有自定义工厂就使用自定义工厂没有自定义工厂就使用DefaultPropertySourceFactoryPropertySourceFactory factory (factoryClass PropertySourceFactory.class ?DEFAULT_PROPERTY_SOURCE_FACTORY : BeanUtils.instantiateClass(factoryClass));// 遍历各个location地址for (String location : locations) {try {// location地址支持占位符的形式String resolvedLocation this.environment.resolveRequiredPlaceholders(location);// 获取ResourceResource resource this.resourceLoader.getResource(resolvedLocation);addPropertySource(factory.createPropertySource(name, new EncodedResource(resource, encoding)));}catch (IllegalArgumentException | FileNotFoundException | UnknownHostException | SocketException ex) {// Placeholders not resolvable or resource not found when trying to open itif (ignoreResourceNotFound) {if (logger.isInfoEnabled()) {logger.info(Properties location [ location ] not resolvable: ex.getMessage());}}else {throw ex;}}} }总的来说Spring处理PropertySource的源代码非常简单这边就不再过多赘述了。
http://www.zqtcl.cn/news/538855/

相关文章:

  • 开锁做网站怎么样榆林网站开发公司
  • 松原市建设局网站苏州网站建设-中国互联
  • 标书制作教程视频网站福田祥菱v1单排
  • 点网站出图片怎么做能看人与动物做的网站
  • 免费开源建站系统源码wordpress公共函数在哪里
  • 西昌市建设工程管理局网站模块化网站开发
  • 无限看片的视频大全免费下载上海网络优化方法
  • 物流公司做网站注重什么问题中国建设银行征信中心网站
  • 教务处网站建设专业做鞋子的网站吗
  • 梦幻创意网站建设成都做网站设计哪家便宜
  • 织梦网站栏目修改教程丝绸之路网站建设意义
  • 如何知道一个网站是谁做的北京装饰公司前十名
  • 杭州网站建设哪个平台好visualstudio 做网站
  • 广州站是哪个站h5建站系统
  • 网站首页网址应该有对应的域名南京高端模板建站
  • 自己做的网站竞价优化怎么做网站流量赚钱吗
  • 人力资源网站建设mip网站模板
  • 太原市住房和城乡建设部网站网站 备案 换空间
  • 怎么做网站备份网站运营数据周报表怎么做
  • 度更新网站做详情页网站
  • 酷炫网站模板wordpress自动发货插件
  • 网站做多个镜像wordpress无法显示向导
  • 交易类网站建设费用工厂招工最新招聘信息
  • 俄语网站建设网站建设的实训报告
  • 朝阳市做网站的公司wordpress msg
  • 企业管理系统免费版seo关于网站
  • 几度设计网站设计制作平板电脑支架
  • 游戏设计 网站上海中企动力做网站多少钱
  • flash 开发的网站网上国网app推广经验
  • pyhton可以做网站吗文章wordpress