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

特色的岑溪网站开发wordpress 左右风格主题

特色的岑溪网站开发,wordpress 左右风格主题,网络推广网站培训,xammp wordpress文章目录 前言一、使用场景二、使用步骤1.错误示例2.ConditionalOnProperty的解决方案 总结 前言 ConditionalOnProperty 是Spring Boot中的条件注解#xff0c;它的核心功能是通过属性名以及属性值来实现的#xff0c;常被用于判断某个属性是否存在#xff0c;然后决定某个… 文章目录 前言一、使用场景二、使用步骤1.错误示例2.ConditionalOnProperty的解决方案 总结 前言 ConditionalOnProperty 是Spring Boot中的条件注解它的核心功能是通过属性名以及属性值来实现的常被用于判断某个属性是否存在然后决定某个Bean是否创建; 一、使用场景 一般用于是否要创建,或者注入到spring中的bean的条件判断,例如: spring中一定有对于mysql的一些默认配置,但是当我不引入mysql,yml中不做配置的时候,这些类是不会被注入的,当我在yml中引入mysql的相关配置,那么相应的数据源,mysql等相关bean就会被注入其中; 二、使用步骤 这里举个例子,也是项目中常见的问题,当一个实现类有两个实现类的时候,我们注入使用的时候会有问题; 1.错误示例 一个接口 public interface TestConditionOnProperty {void sout(); }两个实现类 Service public class TestConditionOnProperty1 implements TestConditionOnProperty {Overridepublic void sout() {System.out.println( TestConditionOnProperty1 );} }Service public class TestConditionOnProperty2 implements TestConditionOnProperty {Overridepublic void sout() {System.out.println( TestConditionOnProperty2 );} }开始测试, 问题出现 SpringBootTest class TestConditionOnPropertyTest {AutowiredTestConditionOnProperty testConditionOnProperty;Testvoid sout() {testConditionOnProperty.sout();} }TestConditionOnProperty 应该是唯一的,但是找到了两个: expected single matching bean but found 2: testConditionOnProperty1,testConditionOnProperty2 解决方案: 加上Qualifier ,指定其中一个具体实现类 SpringBootTest class TestConditionOnPropertyTest {Qualifier(testConditionOnProperty1)AutowiredTestConditionOnProperty testConditionOnProperty;Testvoid sout() {testConditionOnProperty.sout();} }2.ConditionalOnProperty的解决方案 依然是如上代码,但是改造下,TestConditionOnProperty1 和 TestConditionOnProperty2 各增加一行代码 Service ConditionalOnProperty(name TestConditionOnProperty,havingValue TestConditionOnProperty1) public class TestConditionOnProperty1 implements TestConditionOnProperty {Overridepublic void sout() {System.out.println( TestConditionOnProperty1 );} }Service ConditionalOnProperty(name TestConditionOnProperty,havingValue TestConditionOnProperty2) public class TestConditionOnProperty2 implements TestConditionOnProperty {Overridepublic void sout() {System.out.println( TestConditionOnProperty2 );} }yml增加配置 TestConditionOnProperty: TestConditionOnProperty2ConditionalOnProperty(name “TestConditionOnProperty”,havingValue “TestConditionOnProperty2”)其中 name 与yml配置中的 TestConditionOnProperty对应 对应后,会读取到值为TestConditionOnProperty2, 与当前注解中的havingValue 值比对 结果为true生效,注入当前bean,结果为true失效,不注入当前bean 最终其实就是只注入了一个bean 再次测试 SpringBootTest class TestConditionOnPropertyTest {AutowiredTestConditionOnProperty testConditionOnProperty;Testvoid sout() {testConditionOnProperty.sout();} }总结 其实这个注解 ConditionalOnProperty 相当于就是java SPI机制的另一种实现方式,更加灵活,在配置文件中更改,当注册中心为nacos,可以实现不重启项目就能自如切换相应实现类的效果; 也就是热加载的效果,热加载其实是 RefreshScope 发生的了作用 RefreshScope概述
http://www.pierceye.com/news/108916/

相关文章:

  • 做网站页面大小多大8上的信息课做网站作业
  • 自己做微网站创欧科技 网站建设
  • 网站设计师大学学什么专业北京燕华工程建设有限公司网站
  • 广州专业网站建设企业wordpress 数据库修改
  • 淮南装饰公司网站建设seo 网站树
  • 设计素材下载网站网络营销课程设计报告
  • 安庆公司做网站搜索引擎收录提交入口
  • 城固网站建设wordpress主题谁的最好
  • 国外建站企业北京鑫创网站建设
  • 网站做视频wordpress插件手动升级
  • wordpress收不到网站没有收款接口网站怎么做收款
  • 信阳做网站推广用tornado做网站
  • 网站开发与数据库ppt成都优化网站建设
  • 毕业设计静态网站建设选题依据企业网络营销的优势
  • 网站图片动态换名网站充值支付宝收款怎么做
  • 蜘蛛网是个什么网站做特卖的购物网站
  • 从零学做网站古典 网站模板
  • h5网站模板开发网站后台哪些功能需要前端配合
  • 网站建设 宜宾佛山企业网站自助建站
  • 苏宁易购网站建设 的定位手机网站制作招聘
  • 个人网站备案申请360老是提示危险网站
  • 建网站哪个好 优帮云自己怎么注册域名
  • 做3ds磁铁卡网站大连旅顺博物馆
  • 邢台市住房和城乡建设局网站大连网站推广机构
  • 网站建设开标书房地产网页设计
  • 中国建设建设工程造价管理协会网站建设视频网站要求吗
  • 商务网站教程深圳定制纸箱
  • 湖南手机版建站系统哪家好自己做网站地图
  • 天津网站制作报价阿里云需要网站建设方案书
  • 做最好的美食分享网站网站建设客户需求分析