本文来源于我在InfoQ中文站翻译的文章,原文地址是:http://www.infoq.com/cn/news/2012/07/spring-for-android-1.0近日,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依赖管理。
查看英文原文:SpringSource Brings Spring Framework to Android with Spring for Android 1.0
分享到:
相关推荐
Spring框架 Spring框架可在任何类型的部署平台上为基于Java的现代企业应用程序提供全面的编程和配置模型。 Spring的一个关键元素是在应用程序级别的基础架构... 请考虑通过spring-framework-issues GitHub存储库提交复
spring-framework-3.0.5.RELEASE-dependencies 好不容易找到了,赶紧分享一下 因为不能大于20M,共分了8个包,都是...org.springframework.build org.testng org.xmlpull org.joda org.jruby org.junit org.objectweb.asm
Spring 3.0是Spring框架的一次重大更新,而根据SpringSource副总裁Shaun Connolly的描述,Spring框架是当下最流行的Java开发框架。 全新的Spring 3.0提供了全面的RESTful Web服务支持,以及一个新的表达式语言。其...
com.springsource.net.sf.cglib-2.2.0.jar com.springsource.org.aopalliance-1.0.0.jar commons-logging-1.2.jar druid-1.0.9.jar mysql-connector-java-5.1.46-bin.jar spring-framework-5.2.6.RELEASE
官方原版源码 spring-framework-5.1.15.RELEASE.zip
其中最小依赖包:org.springframework.core、org.springframework.context、org.springframework.beans、org.springframework.asm、org.springframework.expression、com.springsource.org.apache.commons.logging
org.springframework.beans-3.0.5工程所需jar包,com.springsource.net.sf.cglib-2.2.0.jar、 com.springsource.org.apache.commons.logging-1.1.1.jar、 javax.inject.jar、 javax.servlet.jsp.jar、 org.spring...
spring-framework-3.0.5.RELEASE-dependencies 好不容易找到了,赶紧分享一下 因为不能大于20M,共分了8个包,都是...org.springframework.build org.testng org.xmlpull org.joda org.jruby org.junit org.objectweb.asm
spring-framework-3.0.5.RELEASE-dependencies 好不容易找到了,赶紧分享一下 因为不能大于20M,共分了8个包,都是...org.springframework.build org.testng org.xmlpull org.joda org.jruby org.junit org.objectweb.asm
spring-framework-3.0.5.RELEASE-dependencies 好不容易找到了,赶紧分享一下 因为不能大于20M,共分了8个包,都是...org.springframework.build org.testng org.xmlpull org.joda org.jruby org.junit org.objectweb.asm
spring-framework-3.0.5.RELEASE-dependencies 好不容易找到了,赶紧分享一下 因为不能大于20M,共分了8个包,都是...org.springframework.build org.testng org.xmlpull org.joda org.jruby org.junit org.objectweb.asm
spring-aop-4.0.0.RELEASE;spring-aspects-4.0.0.RELEASE;spring-beans-4.0.0.RELEASE;spring-context-4.0.0.RELEASE;spring-core-4.0.0.RELEASE;spring-expression-4.0.0.RELEASE;spring-jdbc-4.0.0.RELEASE;spring...
org.springframework.aop-3.1.0.RELEASE.jar org.springframework.asm-3.1.0.RELEASE.jar org.springframework.aspects-3.1.0.RELEASE.jar org.springframework.beans-3.1.0.RELEASE.jar org.springframework....
Jointly developed by SpringSource and Accenture, Spring Batch fills this critical gap by providing a robust and convenient framework for writing batch applications that process large volumes of ...
This book is for Java developers who would like to rapidly gain hands-on experience with Java/Java EE development using the Spring framework. If you are already a developer using Spring in your ...
spring-framework-3.0.5.RELEASE-dependencies 好不容易找到了,赶紧分享一下 因为不能大于20M,共分了8个包,都是...org.springframework.build org.testng org.xmlpull org.joda org.jruby org.junit org.objectweb.asm
spring-framework-3.0.5.RELEASE-dependencies 好不容易找到了,赶紧分享一下 因为不能大于20M,共分了8个包,都是...org.springframework.build org.testng org.xmlpull org.joda org.jruby org.junit org.objectweb.asm
spring 3.2.0 源码文件 SpringSource-spring-framework-v3.2.0.M1-1-g94f8393.zip
spring-framework-3.0.5.RELEASE-dependencies 好不容易找到了,赶紧分享一下 因为不能大于20M,共分了8个包,都是...org.springframework.build org.testng org.xmlpull org.joda org.jruby org.junit org.objectweb.asm
One of the first (if not the first) books on the latest Spring 3.x, and the first Spring code Recipes book focused on Spring Web-tier development The Spring framework is growing. It has always been ...