首页 文章 精选 留言 我的

精选列表

搜索[端到端加密],共10000篇文章
优秀的个人博客,低调大师

Spring cloud配置客户端(三)

覆盖远程配置属性 默认情况,Spring Cloud是允许覆盖的,spring.cloud.config.allowOverride=true通过程序启动参数,调整这个值为"false" --spring.cloud.config.allowOverride=true 启动后,重新Postman发送POST请求,调整spring.application.name值为"spring-cloud-new" 重点:如果spring.application.name不写的话,默认的话是项目名 自定义Bootstrap配置 创建META-INF/spring.factories文件{类似于Spring boot 自定义Starter} 自定义Bootstrap配置Configurtion package com.segmentfault.springcloudlesson1.bootstrap; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; import java.util.HashMap; import java.util.Map; /** * bootstrap 配置bean */ @Configuration public class MyConfiguration implements ApplicationContextInitializer { @Override public void initialize(ConfigurableApplicationContext applicationContext) { //从ConfigurableApplicationContext获取ConfigurableEnvironment实例 ConfigurableEnvironment environment = applicationContext.getEnvironment(); //获取PropertySources MutablePropertySources propertySources = environment.getPropertySources(); //定义一个新的 propertySource,并放置在首位 propertySources.addFirst(createPropertySource()); } private PropertySource createPropertySource() { Map<String, Object> source = new HashMap<>(); source.put("name", "shuai"); PropertySource propertySource = new MapPropertySource("my-property-source", source); return propertySource; } } 三. 配置MEAT-INF/spring.factories文件,关联Key org.springframework.cloud.bootstrapConfiguration= \ com.segmentfault.springcloudlesson2.bootstrap.Myconfiguration 自定义Bootstrap配置属性源 实现PropertySourceLocator package com.segmentfault.springcloudlesson1.bootstrap; import org.springframework.cloud.bootstrap.config.PropertySourceLocator; import org.springframework.core.env.*; import java.util.HashMap; import java.util.Map; /** * 自定义{@link PropertySourceLocator}实现 */ public class MyPropertySourceLocator implements PropertySourceLocator { @Override public PropertySource<?> locate(Environment environment) { if (environment instanceof ConfigurableEnvironment) { ConfigurableEnvironment configurableEnvironment = ConfigurableEnvironment.class.cast(environment); //获取PropertySources MutablePropertySources propertySources = configurableEnvironment.getPropertySources(); //定义一个新的 propertySource,并放置在首位 propertySources.addFirst(createPropertySource()); } return null; } private PropertySource createPropertySource() { Map<String, Object> source = new HashMap<>(); source.put("spring.application.name", "shuaishuai"); //设置名称和来源 PropertySource propertySource = new MapPropertySource("over-bootstrap", source); return propertySource; } } 配置META-INF/spring.factories org.springframework.cloud.bootstrapConfiguration= \ com.segmentfault.springcloudlesson1.bootstrap.MyConfiguration,\ com.segmentfault.springcloudlesson1.bootstrap.MyPropertySourceLocator

优秀的个人博客,低调大师

区分不同手机平台客户端

Conclusion:Unlike User-Agent ,which let the browser describe its meta data and information , the two kinds of client by default will not have a pre-defined field which can function like this. Solution:(We created aself-defined fieldin the http header) For example ,we create a field namedMobile-Agent In client side: when we construct the http request ,we add the value of header “Mobile-Agent” to be some value Android Client codeonly need to set the “Mobile-Agent” header to be ”Android”. Code example: (see myhighlighted) publicJSONObjectcallJSONWebService(Stringurl){ HttpParamsmy_httpParams=newBasicHttpParams(); HttpConnectionParams.setConnectionTimeout(my_httpParams,conn_timeout); HttpConnectionParams.setSoTimeout(my_httpParams,conn_timeout); HttpClienthttpClient=newDefaultHttpClient(my_httpParams); HttpGethttpRequest=newHttpGet(url); httpRequest.setHeader("User-Agent","bleumagent"); httpRequest.setHeader(“Mobile-Agent”,”Android”); HttpResponsehttpResponse=null; JSONObjecthttpJsonResult=null; Stringresult=null; try{ httpResponse=httpClient.execute(httpRequest); if(httpResponse.getStatusLine().getStatusCode()==200){ HttpEntityhttpEntity=httpResponse.getEntity(); if(httpEntity!=null){ InputStreaminputStream=httpEntity.getContent(); result=this.convertStreamToString(inputStream); httpJsonResult=newJSONObject(result); inputStream.close(); } } }catch(Exceptione){ System.out.println("callJsonWebServicefailed."); e.printStackTrace(); } httpClient.getConnectionManager().shutdown(); returnhttpJsonResult; } IPhoneClient codecan use Objective-C to do the similar thing ,just set the “Mobile-Agent” header to be “IPhone” In server side’s servlet : we only use the Servlet API to resolve “Mobile-Agent” field. Then solved. 本文转自 charles_wang888 51CTO博客,原文链接:http://blog.51cto.com/supercharles888/835904,如需转载请自行联系原作者

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册