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

wordpress取消邮件西安seo天勤网络营销

wordpress取消邮件,西安seo天勤网络营销,哪里有做设备的,网站地图做几个一、需求说明 本机启动含有XXL-job的工程,发现每次都会进行XXL-job的init的动作。这会导致本机每次启动都会把自己注册到XXL-job的服务端。但是我明明本地调试的功能不想要是编写定时任务,于是想了下,是否可以设计一个开关,让本机…

一、需求说明

本机启动含有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;@Data@NoArgsConstructorpublic 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 时,创建该 Bean@Beanpublic MyFeature myFeature() {return new MyFeature();}
}

在上面的示例中,如果应用程序配置文件中名为 “myapp.feature.enabled” 的属性值为 “true”,则该 MyFeatureAutoConfiguration 配置类中的 myFeature() 方法将被调用创建一个 MyFeature 的实例并将其注入到应用程序上下文中,否则 MyFeature 不会被创建。

http://www.yayakq.cn/news/251639/

相关文章:

  • 网站动态效果用什么软件做的中国十大贸易公司排名
  • 网站开发项目需求文档h5源码
  • 注册公司那家网站做的比较好乐陵seo公司
  • 谷歌做自己的网站简约wordpress免费主题
  • 深圳勘察设计协会网站在线申请
  • 科技设计网站有哪些内容专业团队文案
  • 威海营销型网站建设网站建设模块
  • 做暧暖免费观看网站上海公司注册地址
  • 如何利用ps做网站网站备案信息查询
  • 苏州公司网站做的网站有营销效果吗
  • 网站建设及维护成本jsp借书网站开发
  • 电子商务网站建设的可行性分析wordpress导航站的源码
  • 信息发布型网站wordpress 博客统计
  • 新建网站软件装修网站横幅怎么做
  • 公司企业网站程序如何做企业网站界面
  • 做办公用品网站资料怎么收集荣耀商城
  • 江苏连云港网站建设公司佛山网站建设公司哪个性比价好些
  • 福清市建设局官方网站派多格宠物网站建设
  • 怎么做淘宝链接网站免费国外在线代理服务器
  • 广州白云住房和建设局网站企业云服务
  • 网站建设构架南昌网站排名推广
  • 像wordpress一样的网站兰州市城市建设设计院网站
  • 网站建设销售怎样做淘宝券网站
  • 建网站素材网站页面设计代码
  • 如何给公司注册网站仿70网站分类目录源码
  • 哪些网站是动态码上游二维码制作
  • 住建部城乡建设网站上饶哪里可以学网站建设
  • 网站建设创意网站免费正能量软件下载视频
  • 巫山那家做网站十大app软件排行榜
  • 前几年很火的网站建设公司注册建设网站的公司网站