近日,SpringSource发布了Spring for Android 1.0。Spring for Android是Spring Framework的扩展,有助于简化原生Android应用的开发。此次发布最为引入关注之处是提供了一个REST客户端(RestTemplate)以及对OAuth的支持(Spring Social)。

Spring for Android 1.0的首个主要特性就是REST客户端。你现在可以通过Spring RestTemplate抽象层在原生Android应用中使用RESTfule服务了。根据Google的建议,RestTemplate对 Android 2.3+使用了J2SE HTTP客户端库,对Android 2.2及之前的版本使用了HttpClient。它支持不同的HTTP消息转换器、使用Jackson或Gson实现JSON编排、使用Simple XML Serializer实现XML编排、使用Android ROME实现RSS/Atom编排。RestTemplate还支持gzip压缩。下面这个简单的RestTemplate示例来自于Spring for Android参考手册,该示例使用搜索关键词“SpringSource”来搜索Google。

String url = "https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q={query}"; RestTemplate restTemplate = new RestTemplate(); restTemplate.getMessageConverters().add(new StringHttpMessageConverter()); String result = restTemplate.getForObject(url, String.class, "SpringSource"); 

Spring for Android 1.0的另一个主要特性就是对Spring Social的支持。你现在可以在Android应用中使用Spring Social,这包括一个OAuth客户端和诸如Twitter与Facebook等流行社交站点的实现。此次发布提供了对OAuth 1.x与2.0的支持,并且包含一个SQLite库以及兼容于Android的Spring Security加密。

熟悉Spring Framework的开发者自然而然地期望Spring for Android能够支持依赖注入。然而,由于Android通过Intent来驱动应用生命周期的方式,依赖注入方式的实现会很受限。感兴趣的读者请阅读Clean Code in Android Applications来了解关于Android中使用依赖注入的更多信息。

要想了解更多信息,请参阅Spring for Android参考手册。Spring for Android的示例位于GitHub上。若想起步,请下载发布包或是添加Maven依赖。

<dependency> <groupId>org.springframework.android</groupId> <artifactId>spring-android-rest-template</artifactId> <version>1.0.0.RELEASE</version> </dependency>  <dependency> <groupId>org.springframework.android</groupId> <artifactId>spring-android-auth</artifactId> <version>${spring-android-version}</version> </dependency> 

要想在Android应用中利用Maven的依赖管理功能,请不要忘记阅读Maven依赖管理。

更多相关文章

  1. Maven开发Android指南
  2. Android(安卓)SQLite使用方法
  3. android - 为安全而设计 - 2 - 开发文档翻译
  4. android下socket的ip配置
  5. Android(安卓)UI开发第二十八篇——Fragment中使用左右滑动菜单
  6. android - 为安全而设计 - 2 - 开发文档翻译
  7. 在Android程序中使用全局变量
  8. android studio 使用android:drawableTop与**顶部失真
  9. android - 为安全而设计 - 2 - 开发文档翻译

随机推荐

  1. TextView 部分字符高亮 android
  2. android --拍照相册选取图片[兼容小米等
  3. Android中AppWidget加载流程(二)
  4. 【Android】Vitamio 4.0 正式版发布/ Vit
  5. 个人android工具包——androidkit更新
  6. android HAL层
  7. android安全:flag FLAG_RECEIVER_REGISTER
  8. 安装、卸载和运行程序
  9. Android(安卓)手机sdcard目录或文件的拷
  10. 快速解决Android(安卓)10选取相册失败(Pe