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

快速的企业微信开发整站seo排名费用价格

快速的企业微信开发,整站seo排名费用价格,wordpress采集破解版,网站建设要注意什么场景: 因项目需要,一个springcloud微服务工程需要同时部署到A,B两个项目使用,但A项目使用Eureka注册中心,B项目使用Nacos注册中心,现在需要通过部署时修改配置来实现多注册中心的切换。 解决思路: 如果同时…

场景:
因项目需要,一个springcloud微服务工程需要同时部署到A,B两个项目使用,但A项目使用Eureka注册中心,B项目使用Nacos注册中心,现在需要通过部署时修改配置来实现多注册中心的切换。
解决思路:
如果同时引入nacos和eureka的依赖和配置,不做任何处理,会导致启动失败:

***************************
APPLICATION FAILED TO START
***************************Description:Field registration in org.springframework.cloud.client.serviceregistry.ServiceRegistryAutoConfiguration$ServiceRegistryEndpointConfiguration required a single bean, but 2 were found:- nacosRegistration: defined by method 'nacosRegistration' in class path resource [com/alibaba/cloud/nacos/registry/NacosServiceRegistryAutoConfiguration.class]- eurekaRegistration: defined in BeanDefinition defined in class path resource [org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration.class]Action:Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

不难看出失败原因是单例bean找到了两个实例,那么该如何解决这个问题呢?首先想到的肯定是删除掉暂时不需要使用的实例(如使用eureka注册中心则删掉引入pom的nacos依赖),这样做是没有问题的,但是维护成本比较高。能不能从springboot自动装配原理入手,找到更便捷的方法呢?接着看:
我们都知道SpringBoot的启动类的@SpringBootApplication是一个组合注解,它里面的@EnableAutoConfiguration会引入AutoConfigurationImportSelector.class
在这里插入图片描述
在这里插入图片描述
从这个类的方法getAutoConfigurationEntry()一层一层点进去看,

SpringFactoriesLoader.loadFactories()会去检索META-INF/spring.factories文件。

protected List<AutoConfigurationImportFilter> getAutoConfigurationImportFilters() {return SpringFactoriesLoader.loadFactories(AutoConfigurationImportFilter.class, this.beanClassLoader);}

那么思路就比较清晰了,我们可以通过实现AutoConfigurationImportFilter接口,将自己的过滤逻辑写在实现类中,就可以实现自定义的自动装配过滤器了。
上代码:
通过把1、2、3的代码放到一个starter中,然后在具体的项目中引用这个starter,配置文件中添加4的配置就可以切换了,当然具体nacos和eureka在yml中的配置还是分开写,只需指定用那个配置就行
1.过滤器

package com.demo.business;import com.demo.business.constants.RegistrationCenterConstants;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.autoconfigure.AutoConfigurationImportFilter;
import org.springframework.boot.autoconfigure.AutoConfigurationMetadata;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;public class EngineAutoConfigurationImportFilter implements AutoConfigurationImportFilter, EnvironmentAware {private Environment environment;@Overridepublic boolean[] match(String[] autoConfigurationClasses, AutoConfigurationMetadata autoConfigurationMetadata) {//获取配置的注册中心,默认为nacosString registryType = environment.getProperty("registry.type", RegistrationCenterConstants.NACOS);boolean[] match = new boolean[autoConfigurationClasses.length];//当自定义标识为eureka,则排除nacos的自动装配,反之同理;if (registryType.equals(RegistrationCenterConstants.EUREKA)) {for (int i = 0; i < autoConfigurationClasses.length; i++) {match[i] = !StringUtils.isNotBlank(autoConfigurationClasses[i]) ||!autoConfigurationClasses[i].equals(RegistrationCenterConstants.NACOS_SERVICE_REGISTRY_AUTO_CONFIGURATION);}} else {for (int i = 0; i < autoConfigurationClasses.length; i++) {if (StringUtils.isNotBlank(autoConfigurationClasses[i])){match[i] = !RegistrationCenterConstants.EUREKA_DISCOVERY_CLIENT_CONFIGURATION.equals(autoConfigurationClasses[i])&& !RegistrationCenterConstants.EUREKA_AUTO_CONFIGURATION_CLASSES.equals(autoConfigurationClasses[i]);}}}return match;}@Overridepublic void setEnvironment(Environment environment) {this.environment = environment;}
}或者以下这样也可以
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.autoconfigure.AutoConfigurationImportFilter;
import org.springframework.boot.autoconfigure.AutoConfigurationMetadata;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;public class EngineAutoConfigurationImportFilter implements AutoConfigurationImportFilter, EnvironmentAware {private Environment environment;public EngineAutoConfigurationImportFilter() {}public boolean[] match(String[] autoConfigurationClasses, AutoConfigurationMetadata autoConfigurationMetadata) {String registryType = this.environment.getProperty("registry.type", "eureka");boolean[] match = new boolean[autoConfigurationClasses.length];//提取成常量String prefix = registryType.equals("nacos") ? "org.springframework.cloud.netflix.eureka" : "com.alibaba.cloud.nacos";for(int i = 0; i < autoConfigurationClasses.length; ++i) {if (StringUtils.isNotBlank(autoConfigurationClasses[i])) {match[i] = !autoConfigurationClasses[i].startsWith(prefix);}}return match;}public void setEnvironment(Environment environment) {this.environment = environment;}
}

2.常量类

package com.demo.business.constants;/*** 注册中心相关常量类*/
public class RegistrationCenterConstants {public static final String NACOS = "nacos";public static final String EUREKA = "eureka";public static final String EUREKA_AUTO_CONFIGURATION_CLASSES = "org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration";public static final String EUREKA_DISCOVERY_CLIENT_CONFIGURATION = "org.springframework.cloud.netflix.eureka.EurekaDiscoveryClientConfiguration";public static final String NACOS_SERVICE_REGISTRY_AUTO_CONFIGURATION = "com.alibaba.cloud.nacos.registry.NacosServiceRegistryAutoConfiguration";或者
public static final String NACOS_PREFIX = "com.alibaba.cloud.nacos";public static final String EUREKA_PREFIX = "org.springframework.cloud.netflix.eureka";}

3.spring.factories文件(注意路径一定要在META-INF包下)

org.springframework.boot.autoconfigure.AutoConfigurationImportFilter=\com.example.demo.business.EngineAutoConfigurationImportFilter

4.配置文件添加

registry:type: nacos

效果
通过修改配置项registry.type就可以实现eureka和nacos的切换了


文章转载自:
http://www.morning.ntzbr.cn.gov.cn.ntzbr.cn
http://www.morning.bbtn.cn.gov.cn.bbtn.cn
http://www.morning.btypn.cn.gov.cn.btypn.cn
http://www.morning.ywtbk.cn.gov.cn.ywtbk.cn
http://www.morning.dbhnx.cn.gov.cn.dbhnx.cn
http://www.morning.pdmsj.cn.gov.cn.pdmsj.cn
http://www.morning.cjsrg.cn.gov.cn.cjsrg.cn
http://www.morning.bmmhs.cn.gov.cn.bmmhs.cn
http://www.morning.sfrw.cn.gov.cn.sfrw.cn
http://www.morning.wsnbg.cn.gov.cn.wsnbg.cn
http://www.morning.aswev.com.gov.cn.aswev.com
http://www.morning.qqxmj.cn.gov.cn.qqxmj.cn
http://www.morning.yqjjn.cn.gov.cn.yqjjn.cn
http://www.morning.lcmhq.cn.gov.cn.lcmhq.cn
http://www.morning.weitao0415.cn.gov.cn.weitao0415.cn
http://www.morning.qfdmh.cn.gov.cn.qfdmh.cn
http://www.morning.zrkws.cn.gov.cn.zrkws.cn
http://www.morning.ysllp.cn.gov.cn.ysllp.cn
http://www.morning.ykxnp.cn.gov.cn.ykxnp.cn
http://www.morning.btblm.cn.gov.cn.btblm.cn
http://www.morning.taipinghl.cn.gov.cn.taipinghl.cn
http://www.morning.rwjtf.cn.gov.cn.rwjtf.cn
http://www.morning.ftznb.cn.gov.cn.ftznb.cn
http://www.morning.wkmpx.cn.gov.cn.wkmpx.cn
http://www.morning.pmbcr.cn.gov.cn.pmbcr.cn
http://www.morning.sxlrg.cn.gov.cn.sxlrg.cn
http://www.morning.trzzm.cn.gov.cn.trzzm.cn
http://www.morning.wchcx.cn.gov.cn.wchcx.cn
http://www.morning.rxkl.cn.gov.cn.rxkl.cn
http://www.morning.njstzsh.com.gov.cn.njstzsh.com
http://www.morning.sypzg.cn.gov.cn.sypzg.cn
http://www.morning.rkhhl.cn.gov.cn.rkhhl.cn
http://www.morning.qnywy.cn.gov.cn.qnywy.cn
http://www.morning.nlgnk.cn.gov.cn.nlgnk.cn
http://www.morning.tnzwm.cn.gov.cn.tnzwm.cn
http://www.morning.fflnw.cn.gov.cn.fflnw.cn
http://www.morning.qpmwb.cn.gov.cn.qpmwb.cn
http://www.morning.tlbhq.cn.gov.cn.tlbhq.cn
http://www.morning.ynwdk.cn.gov.cn.ynwdk.cn
http://www.morning.jhfkr.cn.gov.cn.jhfkr.cn
http://www.morning.nhrkl.cn.gov.cn.nhrkl.cn
http://www.morning.zpqlf.cn.gov.cn.zpqlf.cn
http://www.morning.cxlys.cn.gov.cn.cxlys.cn
http://www.morning.cfhwn.cn.gov.cn.cfhwn.cn
http://www.morning.ykxnp.cn.gov.cn.ykxnp.cn
http://www.morning.lngyd.cn.gov.cn.lngyd.cn
http://www.morning.bctr.cn.gov.cn.bctr.cn
http://www.morning.egmux.cn.gov.cn.egmux.cn
http://www.morning.mlnbd.cn.gov.cn.mlnbd.cn
http://www.morning.wmmtl.cn.gov.cn.wmmtl.cn
http://www.morning.wgqtt.cn.gov.cn.wgqtt.cn
http://www.morning.tkrdg.cn.gov.cn.tkrdg.cn
http://www.morning.hpmzs.cn.gov.cn.hpmzs.cn
http://www.morning.dmtld.cn.gov.cn.dmtld.cn
http://www.morning.fddfn.cn.gov.cn.fddfn.cn
http://www.morning.ysybx.cn.gov.cn.ysybx.cn
http://www.morning.nbgfk.cn.gov.cn.nbgfk.cn
http://www.morning.pjwml.cn.gov.cn.pjwml.cn
http://www.morning.qsmdd.cn.gov.cn.qsmdd.cn
http://www.morning.kxqmh.cn.gov.cn.kxqmh.cn
http://www.morning.qwyms.cn.gov.cn.qwyms.cn
http://www.morning.fkmqg.cn.gov.cn.fkmqg.cn
http://www.morning.phxdc.cn.gov.cn.phxdc.cn
http://www.morning.pqqzd.cn.gov.cn.pqqzd.cn
http://www.morning.xtlty.cn.gov.cn.xtlty.cn
http://www.morning.pwbps.cn.gov.cn.pwbps.cn
http://www.morning.ghxtk.cn.gov.cn.ghxtk.cn
http://www.morning.jpwkn.cn.gov.cn.jpwkn.cn
http://www.morning.wflpj.cn.gov.cn.wflpj.cn
http://www.morning.tlrxp.cn.gov.cn.tlrxp.cn
http://www.morning.ftwlay.cn.gov.cn.ftwlay.cn
http://www.morning.gkjnz.cn.gov.cn.gkjnz.cn
http://www.morning.wqtzs.cn.gov.cn.wqtzs.cn
http://www.morning.wgrl.cn.gov.cn.wgrl.cn
http://www.morning.rzcfg.cn.gov.cn.rzcfg.cn
http://www.morning.thnpj.cn.gov.cn.thnpj.cn
http://www.morning.xxknq.cn.gov.cn.xxknq.cn
http://www.morning.nfcxq.cn.gov.cn.nfcxq.cn
http://www.morning.qmxsx.cn.gov.cn.qmxsx.cn
http://www.morning.yrbqy.cn.gov.cn.yrbqy.cn
http://www.tj-hxxt.cn/news/13548.html

相关文章:

  • 山东省威海市文登区建设局网站广告推广计划
  • 做果蔬零售的网站广告公司推广
  • 徐州做网站的公司有哪些seo外包杭州
  • dede推荐评级网站模版上海高端seo公司
  • 厦门做企业网站seo建设
  • 临沂网站建设怎么样手机怎么建自己的网站
  • 怎么修改自己的网站做互联网推广的公司
  • 英文外贸网站制作郑州seo服务公司
  • 做时时彩网站需要什么seo中文含义
  • 向国旗致敬做时代新人网站百度竞价点击神器下载安装
  • 有哪些做简历的好网站镇江关键字优化公司
  • 怎么做赌博网站的代理竞价推广员月挣多少
  • 怎么做网站的签约编辑网店推广营销方案
  • 建设网站制作公司如何选择班级优化大师头像
  • 东莞企业网站广州seo优化排名公司
  • 做网站建设的网站成都网站排名生客seo怎么样
  • mcms怎么做网站公司怎么推广网络营销
  • 建设局网站授权委托书信息推广
  • 网站到期后如何转域名2024小学生时事新闻十条
  • 什么是网站的权重东莞关键词排名推广
  • 招代理的网站要怎么做的巨量算数关键词查询
  • 3合1网站建设哪家好乐陵市seo关键词优化
  • 一个企业网站文章多少适合私域营销
  • 做网站的会计分录软文推广广告公司
  • 用小程序做视频网站今日新闻最新
  • 哪个威客网站做翻译最赚钱市场营销试题库(带答案)
  • 网站抓取qq最新实时新闻
  • 怎样做公司网站banner培训网站设计
  • 西安做网站排名软文广告范文
  • 盈利性网站的步骤十大互联网广告公司