首页 文章 精选 留言 我的

精选列表

搜索[数据库客户端],共10027篇文章
优秀的个人博客,低调大师

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

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

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册