BT

SpringSource Brings Spring Framework to Android with Spring for Android 1.0

by Bienvenido David on Jun 19, 2012 |

SpringSource has released Spring for Android 1.0. Spring for Android is an extension of the Spring Framework that helps simplify the development of native Android applications. This release features a REST client (RestTemplate) and OAuth support (Spring Social).

The first feature of Spring for Android 1.0 is the REST client. You can now use the Spring RestTemplate abstraction to consume RESTful services within your native Android application. Based on Google's recommendations, RestTemplate uses the J2SE HTTP client libraries for Android 2.3+, and HttpClient for Android 2.2 and below. It supports different HTTP Message Converters, and uses Jackson or Gson for JSON marshalling, Simple XML Serializer for XML marshalling, and Android ROME for RSS/Atom marshalling. RestTemplate also supports gzip compression. Here's a basic example of RestTemplate taken from the Spring for Android reference manual, which queries Google for the search term "SpringSource".

	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");

The other major feature of Spring for Android 1.0 is Spring Social support. You now have the ability to use Spring Social in your Android applications, which includes an OAuth client and implementations of popular social websites like Twitter and Facebook. This release provides OAuth 1.x and 2.0 support, and includes a SQLite repository, and Android compatible Spring Security encryption.

Developers familiar with the Spring Framework will naturally expect Dependency Injection to be part of Spring for Android. However, due to the way Android drives the application lifecycle using Intents, the way Dependency Injection can be implemented is limited. Please read Clean Code in Android Applications for more information on Dependency Injection options in Android.

For more information, please read the Spring for Android Reference Manual. Spring for Android examples are available at GitHub. To get started, you can download the release distribution, or add the Maven dependencies.

	<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>

Be sure to read Maven Dependency Management to utilize Maven's dependency management capabilities within an Android application.

Hello stranger!

You need to Register an InfoQ account or to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Spring Android framework by Naresh Chintalcheru

Limited functionality, like to see this framework evolve.

Is that even a good idea? by peter lin

Let me get this straight. Mobile devices need to be efficient and use a little memory as necessary. So the solution is to put spring on it? Shouldn't a server handle all these types of social networking operations? Why bog down a mobile device?

Is this all part of Spring's plans for world domination?

Summer is here! by C Curl

like the article says, just use j2se http libraries with jackson/json. No point in taking in the sugar coated bloatware in spring just to save handful of lines of code.

Re: Is that even a good idea? by Jonathan Allen

It's a horrible idea on the server, let alone a mobile device. But as smart phone CPUs continue to improve, we're probably going to see a lot more poeple trying to get away with this kind of thing.

Re: Is that even a good idea? by peter lin

It's a horrible idea on the server, let alone a mobile device. But as smart phone CPUs continue to improve, we're probably going to see a lot more poeple trying to get away with this kind of thing.


I agree it's horrible either way. Of course, people will still do it. Then again, I'm not a fan of social networking websites, or using Spring from first hand experience.

negative comments?..interesting... by Jeryl Cook

Spring is bloatware???, Spring should only be used on server???

Sounds like some posters need to read on what the Spring framework is suppose to solve first.

Spring Application Framework is simply implements Inversion of Control, and dependency injection, you...which by itself is very light pattern...in this Android release it "Injects" Httpclient, used via RestTemplate..., which one uses anyway when making HTTP client calls...

light reading:
martinfowler.com/articles/injection.html

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

6 Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2013 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT