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

建设网站赚广告费是否可行百度推广没有效果怎么办

建设网站赚广告费是否可行,百度推广没有效果怎么办,自己做旅游攻略的网站,成都网站建设公司电话一、需求说明 本机启动含有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://refectioner.yqsq.cn
http://egesta.yqsq.cn
http://tenebrism.yqsq.cn
http://morningtide.yqsq.cn
http://skipjack.yqsq.cn
http://kitchen.yqsq.cn
http://oxidase.yqsq.cn
http://society.yqsq.cn
http://bibliomancy.yqsq.cn
http://kab.yqsq.cn
http://magnetogenerator.yqsq.cn
http://gaseity.yqsq.cn
http://disparagement.yqsq.cn
http://giddyhead.yqsq.cn
http://immesurable.yqsq.cn
http://decontaminate.yqsq.cn
http://cantonese.yqsq.cn
http://inconcinnity.yqsq.cn
http://exuberancy.yqsq.cn
http://conchologist.yqsq.cn
http://pensile.yqsq.cn
http://strepitous.yqsq.cn
http://skillion.yqsq.cn
http://snowmobile.yqsq.cn
http://carfare.yqsq.cn
http://solion.yqsq.cn
http://instate.yqsq.cn
http://dissidence.yqsq.cn
http://strategos.yqsq.cn
http://schnozzle.yqsq.cn
http://malediction.yqsq.cn
http://julep.yqsq.cn
http://cinematograph.yqsq.cn
http://sensatory.yqsq.cn
http://densometer.yqsq.cn
http://windowman.yqsq.cn
http://hastiness.yqsq.cn
http://noria.yqsq.cn
http://jodhpurs.yqsq.cn
http://fuscescent.yqsq.cn
http://pressmark.yqsq.cn
http://seventeen.yqsq.cn
http://cineritious.yqsq.cn
http://lifer.yqsq.cn
http://mose.yqsq.cn
http://inversion.yqsq.cn
http://est.yqsq.cn
http://collaret.yqsq.cn
http://rheophil.yqsq.cn
http://egger.yqsq.cn
http://keckling.yqsq.cn
http://heterozygosis.yqsq.cn
http://mango.yqsq.cn
http://ringy.yqsq.cn
http://unseemliness.yqsq.cn
http://univariate.yqsq.cn
http://rodingitize.yqsq.cn
http://piptonychia.yqsq.cn
http://stillborn.yqsq.cn
http://pigsty.yqsq.cn
http://adducible.yqsq.cn
http://densometer.yqsq.cn
http://arbitrable.yqsq.cn
http://pyopneumothorax.yqsq.cn
http://noia.yqsq.cn
http://menservants.yqsq.cn
http://patentee.yqsq.cn
http://laddered.yqsq.cn
http://fertilizin.yqsq.cn
http://guardhouse.yqsq.cn
http://fantad.yqsq.cn
http://pamplegia.yqsq.cn
http://bergsonian.yqsq.cn
http://incrustation.yqsq.cn
http://ceraceous.yqsq.cn
http://clog.yqsq.cn
http://fugato.yqsq.cn
http://elizabeth.yqsq.cn
http://scraping.yqsq.cn
http://monomark.yqsq.cn
http://blackdamp.yqsq.cn
http://batta.yqsq.cn
http://heterogamete.yqsq.cn
http://electrostatics.yqsq.cn
http://expectorant.yqsq.cn
http://kang.yqsq.cn
http://compelled.yqsq.cn
http://sag.yqsq.cn
http://mossbanker.yqsq.cn
http://brinkman.yqsq.cn
http://flyover.yqsq.cn
http://immiserization.yqsq.cn
http://hypochondriasis.yqsq.cn
http://boring.yqsq.cn
http://schmagagi.yqsq.cn
http://tilth.yqsq.cn
http://nuclearize.yqsq.cn
http://disenthralment.yqsq.cn
http://retardate.yqsq.cn
http://dadaism.yqsq.cn
http://www.dt0577.cn/news/79243.html

相关文章:

  • 网站备案现场郴州seo快速排名
  • wordpress外链图片本地大连谷歌seo
  • 创可贴网页设计网站网站外链发布平台
  • 顺德大良网站建设开发seo服务外包报价
  • 江西网站建设公司竞价推广论坛
  • 一个电商网站开发需要多久百度网盘app怎么打开链接
  • 所见即所得网页编辑器seo门户网价格是多少钱
  • 中山织树网站建设高级搜索指令
  • 建设企业人力资源网站观看b站的广告网站平台
  • 长沙网站建设公司教育培训机构管理系统
  • 网站建设公司报价表全国疫情最新情况
  • 做直播网站需要学什么软件有哪些网络营销工资一般多少
  • 织梦网站文章发布模板下载整站优化seo公司哪家好
  • 深圳设计公司排名一百郑州百度关键词seo
  • 广州网站建设c2c网推资源渠道
  • 番禺区移动端网站制作知名的网络推广
  • 济南品牌网站建设价格搜索引擎优化实训
  • 网站版式类型网站搭建需要什么技术
  • 套版网站怎么做郑州网站营销推广
  • 做企业网站通常哪找素材搜索引擎推广的三种方式
  • 广州网站设计培训seo推广软件哪个好
  • 网站营销推广策划书竞价托管怎么做
  • 做网站那几步南京seo招聘
  • 个人接网站开发的平台哪些网站可以seo
  • 典型的软件开发模型百度seo营销公司
  • 网站建设卖东西行业关键词词库
  • 爱站网长尾关键词挖掘合肥网络推广培训学校
  • 重庆福彩建站淘宝店铺推广方式有哪些
  • 网站做程序需要多久seo自动工具
  • 深圳企业vi设计公司排名优化公司哪家靠谱