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

如何建单页网站栏目网络营销形式

如何建单页网站栏目,网络营销形式,杭州建设招标网,网站搭建策略与方法有哪些方面Nacos当前命名空间下的配置文件需要跨命名空间读取其他配置文件的内容。可以先通过Nacos提供的API接口获取配置文件内容&#xff0c;然后解析数据将其放入环境的PropertySource中。 相关依赖包 <!-- Nacos依赖包 --> <dependency><groupId>com.alibaba.clo…
Nacos当前命名空间下的配置文件需要跨命名空间读取其他配置文件的内容。可以先通过Nacos提供的API接口获取配置文件内容,然后解析数据将其放入环境的PropertySource中。
  • 相关依赖包
<!-- Nacos依赖包 -->
<dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId><version>2.2.6.RELEASE</version><exclusions><exclusion><groupId>com.alibaba.nacos</groupId><artifactId>nacos-client</artifactId></exclusion></exclusions>
</dependency><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId><version>2.2.6.RELEASE</version><exclusions><exclusion><groupId>com.alibaba.nacos</groupId><artifactId>nacos-client</artifactId></exclusion></exclusions>
</dependency><dependency><groupId>com.alibaba.nacos</groupId><artifactId>nacos-client</artifactId><version>2.3.0</version>
</dependency>
  • 部分代码

@Order(Ordered.HIGHEST_PRECEDENCE)
public class NacosEnvironmentPostProcessor implements EnvironmentPostProcessor {private static final String NACOS_PROPERTY_SOURCE_NAME = "NACOS";private static final String[] dataIds = new String[]{"db-sample.yml"};private static final String LOGIN_URL = "http://$host/nacos/v1/auth/users/login";private static final String CONFIGS_URL = "http://$host/nacos/v1/cs/configs?dataId=&group=&appName=&config_tags=&pageNo=1&pageSize=100&tenant=$tenant&search=blur&accessToken=$accessToken";@Overridepublic void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {if (environment instanceof StandardServletEnvironment || environment instanceof StandardReactiveWebEnvironment) {return;}addPropertySource(environment);}private void addPropertySource(ConfigurableEnvironment environment) {Map<String, Object> systemEnvironment = environment.getSystemEnvironment();Object namespaceIdObj = systemEnvironment.get("NACOS_NAMESPACE");if (null == namespaceIdObj) {return;}String host = String.valueOf(systemEnvironment.get("NACOS_HOST"));String username = String.valueOf(systemEnvironment.get("NACOS_USERNAME"));String password = String.valueOf(systemEnvironment.get("NACOS_PASSWORD"));String group = String.valueOf(systemEnvironment.get("NACOS_GROUP"));String namespaceId = String.valueOf(namespaceIdObj);log.info("{} {} {} {} {}", host, username, password, group, namespaceId);processV2(environment, host, username, password, namespaceId);}private void processV1(ConfigurableEnvironment environment, String host, String username, String password,String namespaceId, String group) {NacosConfigProperties nacosConfigProperties = new NacosConfigProperties();nacosConfigProperties.setEnvironment(new StandardEnvironment());nacosConfigProperties.setServerAddr(host);nacosConfigProperties.setUsername(username);nacosConfigProperties.setPassword(password);nacosConfigProperties.setNamespace(namespaceId);nacosConfigProperties.setGroup(group);ConfigService configService = null;try {configService = NacosFactory.createConfigService(nacosConfigProperties.assembleConfigServiceProperties());} catch (NacosException e) {log.error(e.getMessage(), e);}if (null == configService) {return;}Properties properties = new Properties();for (String dataId : dataIds) {addProperties(dataId, getPropertySources(configService, dataId, group), properties);}environment.getPropertySources().addFirst(new PropertiesPropertySource(NACOS_PROPERTY_SOURCE_NAME, properties));}private List<PropertySource<?>> getPropertySources(ConfigService configService, String dataId, String group) {List<PropertySource<?>> propertySources = null;try {String config = configService.getConfig(dataId, group, 10000);log.info("{} {} config {}", dataId, group, config);propertySources = NacosDataParserHandler.getInstance().parseNacosData(dataId, config, null);} catch (Exception e) {log.error(e.getMessage(), e);}return propertySources;}private void processV2(ConfigurableEnvironment environment, String host, String username, String password,String namespaceId) {if (null != host && host.contains(",")) {host = host.split(",")[0];}Map<String, String> params = new HashMap<>();params.put("username", username);params.put("password", password);String loginResp = HttpClientUtils.sendPost(LOGIN_URL.replace("$host", host), params, "UTF-8");log.info("login response {}", loginResp);LoginDTO loginDTO = JsonUtils.json(loginResp, LoginDTO.class);if (null == loginDTO) {return;}String configsResp = HttpClientUtils.sendGet(CONFIGS_URL.replace("$host", host).replace("$tenant", namespaceId).replace("$accessToken", loginDTO.getAccessToken()), "UTF-8");ConfigDTO configDTO = JsonUtils.json(configsResp, ConfigDTO.class);if (null == configDTO) {return;}List<ConfigDTO.Item> pageItems = configDTO.getPageItems();if (null == pageItems) {return;}Properties properties = new Properties();pageItems.forEach(item -> addProperties(item.getDataId(), getPropertySources(item), properties));environment.getPropertySources().addFirst(new PropertiesPropertySource(NACOS_PROPERTY_SOURCE_NAME, properties));}private List<PropertySource<?>> getPropertySources(ConfigDTO.Item item) {List<PropertySource<?>> propertySources = null;try {propertySources = NacosDataParserHandler.getInstance().parseNacosData(item.getDataId(), item.getContent(), null);} catch (Exception e) {log.error(e.getMessage(), e);}return propertySources;}private void addProperties(String dataId, List<PropertySource<?>> propertySources, Properties properties) {if (null == propertySources || propertySources.isEmpty()) {return;}propertySources.forEach(propertySource -> {Object source = propertySource.getSource();if (source instanceof Map) {Map<String, Object> map = (Map) source;map.forEach((key, value) -> {if (!key.equals("spring.application.name") && !key.startsWith("server")) {int i = dataId.lastIndexOf(".");if (i != -1) {properties.setProperty(dataId.substring(0, i + 1) + key, String.valueOf(value));}}});}});}}
http://www.yidumall.com/news/17454.html

相关文章:

  • 江阴安泰物流有限公司网站谁做的合肥网站快速优化排名
  • 官方网站怎么做乐陵市seo关键词优化
  • 宣传推广策略有哪些百度官方优化软件
  • 如何下载wordpress网站建设优化公司
  • 大连建设工程信息网官网首页seo入门教程视频
  • 网站 公司 备案石家庄抖音seo
  • 公司门户app北京seo网站开发
  • 网站的架构与建设如何修改百度上面的门店号码
  • 网站音频播放器源码网站关键词如何优化
  • 我有虚拟服务器怎么快速做网站网络营销流程
  • 管理部门网站建设说明最新消息新闻
  • wordpress 访问限制seo的中文含义是什么
  • 长春网站建设找新生科技怎么做百度关键词排名
  • 做网站猫要做端口映射吗seo上排名
  • 怎么用记事本做网站网站子域名查询
  • 京东优惠券网站建设seo技术教程博客
  • 上海正规做网站公司报价如何创建网站?
  • 湛江网站制作工具百度指数官网入口
  • wordpress 出现广告seo是搜索引擎营销吗
  • 广州网站建设是什么企业推广策划方案
  • 做文库网站怎么赚钱网上营销的方式
  • 可以做软件外包项目的网站seo是什么职位
  • 产品开发是做什么的网站seo排名优化价格
  • 自己做的网站和ie不兼容seo交流
  • 新媒体 数字营销 网站建设搜索引擎收录查询
  • 有什么网站是做投资的外链交易平台
  • seo兼职优化网站优化效果
  • 58同城推广网站怎么做西安百度关键词排名服务
  • 怎么使用模板建设网站武汉百度开户代理
  • 聊城做网站多少钱seo常规优化