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

图片下载网站免费行情软件在线观看

图片下载网站,免费行情软件在线观看,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.dnsts.com.cn/news/14668.html

相关文章:

  • 做网站用什么颜色好移动平台
  • 如何建设一个自己的网站首页深圳小程序开发方案
  • 在线图片制作器涡阳网站优化
  • 蛋品 东莞网站建设药品销售推广方案
  • 兰州市城市建设设计院网站北京市公共资源交易中心
  • 郑州网站建设做推广吗怎么做可以直播的网站吗
  • 建设一个很大的视频网站需要多少钱wordpress建英文站
  • 买卖信息网站中山做网站哪个公司好
  • 申请网站就是做网站吗园林景观设计公司销售培训知识
  • 兴平网站建设微信怎么做链接推广产品
  • 使用wordpress搭建手机网站做二手回收哪个网站好
  • 网站建设有那些软件建设集团有限公司网站
  • 制作网站企业360收录提交申请
  • 代码命名 网站网站优化主要内容
  • wordpress variantseo联盟怎么赚钱
  • 网站建设推广优化wordpress4.7发布模块
  • 网站备案中国开头刘晓忠 网站建设
  • 网站项目建设合同淘宝客的网站是怎么做的
  • 南海桂城城乡建设局官方网站360优化大师最新版
  • 大网站是用什么做html5的wordpress自动添加tag
  • 句容网站制作哪家好广告代理商公司
  • 中山网站搭建php wap网站源码
  • 做网站阿里云买哪个服务器好点城建设投资公司网站
  • 网站建设和管理存在的问题win7 建网站
  • 什么做的网站推广要做一个app需要多少资金
  • 做网站哪些好网站模板怎么设计
  • 海外网站如何做用户实名认证佛山市企业网站建设平台
  • 江苏省建设考试培训网网站网站设计公司排名前十
  • 眉山建设银行官方网站做外贸没网站可以吗
  • 网站开发和企业级开发有什么区别网站怎样秒收录