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

三明网站建设tudoulywordpress省理工大学

三明网站建设tudouly,wordpress省理工大学,场口一站式建站哪家公司好,wordpress的app怎么用一、需求说明 本机启动含有XXL-job的工程#xff0c;发现每次都会进行XXL-job的init的动作。这会导致本机每次启动都会把自己注册到XXL-job的服务端。但是我明明本地调试的功能不想要是编写定时任务#xff0c;于是想了下#xff0c;是否可以设计一个开关#xff0c;让本机…一、需求说明 本机启动含有XXL-job的工程发现每次都会进行XXL-job的init的动作。这会导致本机每次启动都会把自己注册到XXL-job的服务端。但是我明明本地调试的功能不想要是编写定时任务于是想了下是否可以设计一个开关让本机的服务不注册到XXL-job的服务端呢。我们可以新增一个Boolean 类型的字段enabled用于动态控制注册动作。即在沙箱环境可以配置成是打开的但是在本机可以配置成是关闭的。 二、实现思路 2.1 方式1、使用if语句 Configuration Slf4j public class XxlJobConfig {Value(${xxl.job.admin.addresses})private String adminAddresses;Value(${xxl.job.accessToken})private String accessToken;Value(${xxl.job.executor.appname})private String appname;Value(${xxl.job.executor.address})private String address;Value(${xxl.job.executor.ip})private String ip;Value(${xxl.job.executor.port})private int port;Value(${xxl.job.executor.logpath})private String logPath;Value(${xxl.job.executor.logretentiondays})private int logRetentionDays;/*** 开关默认关闭*/Value(${xxl.job.enabled})private Boolean enabled;Beanpublic XxlJobSpringExecutor xxlJobExecutor() {if (enabled) {log.info( xxl-job config init.);XxlJobSpringExecutor xxlJobSpringExecutor new XxlJobSpringExecutor();xxlJobSpringExecutor.setAdminAddresses(adminAddresses);xxlJobSpringExecutor.setAppname(appname);xxlJobSpringExecutor.setAddress(address);xxlJobSpringExecutor.setIp(ip);xxlJobSpringExecutor.setPort(port);xxlJobSpringExecutor.setAccessToken(accessToken);xxlJobSpringExecutor.setLogPath(logPath);xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);return xxlJobSpringExecutor;}return null;}}xxl:job:accessToken: ${XXL_JOB_ACCESSTOKEN:XXL_JOB_ACCESSTOKEN}admin:addresses: ${XXL_JOB_ADMIN_ADDRESS:XXL_JOB_ADMIN_ADDRESS}enabled: trueexecutor:address: ${XXL_JOB_EXECUTOR_ADDRESS:XXL_JOB_EXECUTOR_ADDRESS}appname: ${XXL_JOB_EXECUTOR_APPNAME:XXL_JOB_EXECUTOR_APPNAME}ip: ${XXL_JOB_EXECUTOR_IP:XXL_JOB_EXECUTOR_IP}logpath: ${XXL_JOB_EXECUTOR_LOGPATH:XXL_JOB_EXECUTOR_LOGPATH}logretentiondays: ${XXL_JOB_EXECUTOR_LOGRETENTIONDAYS:30}port: ${XXL_JOB_EXECUTOR_PORT:9999}2.2 方式2、使用ConditionalOnProperty注解 以下是核心的配置 ConditionalOnProperty(prefix “xxl.job”, name “enabled”, havingValue “true”) 以下是核心的配置类代码 Slf4j Configuration EnableConfigurationProperties(XxlJobProperties.class) AllArgsConstructor ConditionalOnProperty(prefix xxl.job, name enabled, havingValue true) public class XxlJobConfig {private final XxlJobProperties xxlJobProperties;Beanpublic XxlJobSpringExecutor xxlJobExecutor() {log.info( xxl-job config init.);XxlJobSpringExecutor xxlJobSpringExecutor new XxlJobSpringExecutor();xxlJobSpringExecutor.setAdminAddresses(xxlJobProperties.getAdminAddresses());xxlJobSpringExecutor.setAccessToken(xxlJobProperties.getAccessToken());XxlJobProperties.Executor executor xxlJobProperties.getExecutor();xxlJobSpringExecutor.setAppname(executor.getAppname());xxlJobSpringExecutor.setAddress(executor.getAddress());xxlJobSpringExecutor.setIp(executor.getIp());xxlJobSpringExecutor.setPort(executor.getPort());xxlJobSpringExecutor.setLogPath(executor.getLogPath());xxlJobSpringExecutor.setLogRetentionDays(executor.getLogRetentionDays());return xxlJobSpringExecutor;} }Data ConfigurationProperties(prefix xxl.job) public class XxlJobProperties {private Boolean enabled;private String adminAddresses;private String accessToken;private Executor executor;DataNoArgsConstructorpublic static class Executor {private String appname;private String address;private String ip;private int port;private String logPath;private int logRetentionDays;} }xxl:job:access-token: ${XXL_JOB_ACCESS_TOKEN:XXL_JOB_ACCESS_TOKEN}admin-addresses: ${XXL_JOB_ADMIN_ADDRESSES:XXL_JOB_ADMIN_ADDRESSES}enabled: ${XXL_JOB_ENABLED:XXL_JOB_ENABLED}executor:address: ${XXL_JOB_EXECUTOR_ADDRESS:XXL_JOB_EXECUTOR_ADDRESS}appname: ${XXL_JOB_EXECUTOR_APPNAME:XXL_JOB_EXECUTOR_APPNAME}ip: ${XXL_JOB_EXECUTOR_IP:XXL_JOB_EXECUTOR_IP}logpath: ${XXL_JOB_EXECUTOR_LOGPATH:XXL_JOB_EXECUTOR_LOGPATH}logretentiondays: ${XXL_JOB_EXECUTOR_LOG_RETENTION_DAYS:30}port: ${XXL_JOB_EXECUTOR_PORT:9999}三、ConditionalOnProperty介绍 3.1 ConditionalOnProperty作用 ConditionalOnProperty 是 Spring Boot 框架中的一个注解它用于根据应用程序配置的属性值条件性地加载或配置 Bean。在Springboot中有时候需要控制配置类是否生效可以使用ConditionalOnProperty注解来控制Configuration是否生效。 即通过ConditionalOnProperty控制配置类是否生效可以将配置与代码进行分离实现了更好的控制配置。 3.2 ConditionalOnProperty的实现 具体来说ConditionalOnProperty 允许您在运行时基于应用程序配置的属性值来控制 Bean 是否应该被创建或配置。该注解有一个name属性指定应用程序配置文件中的属性名和一个havingValue属性指定该属性的值。如果应用程序配置文件中的属性名存在且其值与havingValue属性相同那么与该注解标注的Bean将会被创建或配置否则不会。 ConditionalOnProperty实现是通过havingValue与配置文件中的值对比返回为true则配置类生效反之失效。 ConditionalOnProperty(prefix “xxl.job”, name “enabled”, havingValue “true”) 3.3 ConditionalOnProperty举例 举个例子下面的代码片段展示了如何在一个Spring Boot应用中使用 ConditionalOnProperty 注解 Configuration ConditionalOnProperty(name myapp.feature.enabled,havingValue true) public class MyFeatureAutoConfiguration {// 配置项 myapp.feature.enabled 值为 true 时创建该 BeanBeanpublic MyFeature myFeature() {return new MyFeature();} }在上面的示例中如果应用程序配置文件中名为 “myapp.feature.enabled” 的属性值为 “true”则该 MyFeatureAutoConfiguration 配置类中的 myFeature() 方法将被调用创建一个 MyFeature 的实例并将其注入到应用程序上下文中否则 MyFeature 不会被创建。
http://www.hkea.cn/news/14545176/

相关文章:

  • 有哪些外贸网站浙江广厦建设职业技术学院网站
  • 怎么做网上卖菜网站企业做网站推广产品需要多少钱
  • 外汇网站建设制作wordpress访问格式丢失
  • 网站建设廴金手指花总壹陆企业建站找哪家
  • 做网站一般多钱潍坊市网站建设公司
  • 做网站横幅的图片做网站外贸怎么找客户
  • 猪八戒网站 怎么做兼职设计师培训班多少钱一个月
  • 国外怎么做网站网站开发类参考文献
  • 烟台房地产网站建设网站开发周期表
  • 全国做的最棒的网站网页设计图片怎么居中对齐
  • 怎样做门户网站宁波网站推广优化公司
  • 广州建网站开发seo型企业网站wordpress 产品货号
  • 合肥网站建设电话直播网站开发多少钱
  • 手机网站优化公司wordpress 禁用修订版本
  • 访问国外网站很慢泉州网站建设推广服务
  • 网站制作的页面比例百度指数功能有哪些
  • 宁德网站建设做推广的装修网站
  • 临沂做网站建设公司统一登录入口
  • 域名备案的网站建设方案书模板网站备案查询工信部管理系统
  • gta5办公室网站建设中搭建一个网站多少钱哈尔滨电脑
  • 福州小型网站建设qq网页版在线登录
  • 一键发布多个自媒体平台seo排名优化seo
  • 进入公众号免费获取验证码杭州seo公司
  • 海南省建设厅官方网站搜索引擎优化基本
  • 美术馆网站建设要求深圳燃气公司有哪几家
  • 嘉兴建设公司网站服务公司logo
  • 产品网站建设建议开封市建设局网站
  • 中山市有做网站优化的吗中国外贸人才网官网
  • 鹿泉微信网站建设wdcp和wordpress
  • 哪里建设网站最好用深圳网站建设_请到中投网络