This Week in Spring - June 12th, 2012

Engineering | Josh Long | June 13, 2012 | ...

Welcome back to another installment of This Week in Spring. We've got a lot to cover this week, so let's get to it!

  1. Gordon Dickens is at it again, this time with a great look at Spring 3.1's constructor namespace, which provides the logical counterpart to the p: namespace element.
  2. Matt Vickery's at it again! He's got an interesting post on how to use the C24 iO product with Spring.
  3. The Vaadin blog has an interesting post on serialization with the Vaadin web framework and Spring.
  4. The Java Code Geeks has a blog post on using the RESTEasy REST framework with Spring-based services. While I would recommend the Spring REST support in Spring MVC over this approach, it's at least interesting to have the recipe if you ever need to use it.
  5. The Java Code Geeks blog has another post on building Spring-based JPA services that sit behind a RESTful CXF backend. This is another one of those situations where, while it's useful to know how to do in case you need to, you're better off using Spring MVC's REST support. It's easier, and integrates more naturally with the component model.
  6. The Banging My Head Against a Wall blog has a great post on Upgrading from Spring 2.5 to 3.1. This blog shows that the migration is dead simple, if you haven't already made the jump, and he's got insight into one particular little gotcha you might hit to make the migration that much smoother.
  7. The TeamExtension blog has a quick post introducing how to get started with Spring Mobile 1.0. They recommend stock Eclipse with the m2e support, but of course, if you use the SpringSource Tool Suite, you won't have to set anything up.
  8. Are you a .NET developer looking for a solid dependency injection framework like Spring? Have you heard about Spring.NET, the dependency injection framework from the same people behind SpringSource? Blogger Łukasz Budnik has an interesting post about Spring.NET's superiority over other alternatives in the space (Microsoft's Unity and Ninject).

Highlights of Spring for Apache Hadoop 1.0.0 M2

Engineering | Costin Leau | June 13, 2012 | ...

I am happy to announce that the second milestone (1.0.0.M2) of Spring for Apache Hadoop project is available. In this blog post, I would like to quickly highlight the major new features in M2.

HBase DAO support

One of the most versatile and powerful feature in Spring Framework is the Data Access Object (or DAO) support. With Spring for Hadoop 1.0.0 M2, the same functionality was added for HBase. Users of the popular template and callback pattern should feel right at home as the framework handles the table lookup, resource cleanup and exception conversion, letting the developer focus on what really matters. See the API and reference docs for more information. By the way, we also included a new sample in the distribution, hbase-crud, to help you get started right away.

Cascading Taps

In M2, we have expanded the integration with Cascading library by Taps for Spring Framework and Spring Integration resources. The richness of Spring Integration adapters (whether inbound or outbound) such as File, TCP, Twitter, FTP, RSS (just to name a few) is now available to Cascading (and its extensions such as Cascalog or Scalding). And we are just getting started - expect more news on this front.

Hadoop Security

With M2, moving from a vanilla Hadoop install (such as a dev machine) to a fully Kerberos-secured Hadoop cluster is transparent. The File-System, Map/Reduce and Pig components are all security-aware, executing under proper credentials and supporting user impersonation. See the dedicated chapter for more information.

Enhanced vanilla Map/Reduce support

Since the beginning, Spring for Apache Hadoop offered extensive support for Map/Reduce jobs - whether it is vanilla or traditional Java Map/Reduce, streaming or tooling. In M2, we have added support for Hadoop generic options across the board, making job provisioning, either by naming resources individually or through pattern matching, a one-liner. Further more, we have enhanced the bootstrapping of jar-based jobs - rather then requiring the classes to be on the classpath, the job can be fully loaded, in isolation, from the jar. The classes (and their dependencies) do not leak into the application which avoids all sorts of versioning conflicts and dependency creep. The tool declaration has been improved to automatically read the Jar metadata and its Main-Class, offering a powerful, fully managed replacement to Hadoop shell jar invocations.

Two New Samples

Last but not least, two new samples have been added to the distribution: hbase-crud, which I mentioned before showcasing the declarative and programmatic HBase support and pig-scripting, demoing the JVM and Pig scripting: the former doing data preparations in HDFS for the latter, which does data analysis. There are more samples in the pipeline and if you would like to see anything in particular, tell us.

I hope you enjoy this new milestone. Go ahead, grab 1.0.0 M2, take it for a spin and let us know what you think!

Other News: Project Serengeti

As far as new releases go, Spring for Apache Hadoop 1.0.0 M2 is not the only news on the Hadoop front. Today, VMware takes the curtains off project Serengeti, for virtualized and Highly Available Hadoop. See Richard McDougall's blog post on the motivations behind it, the current status…

This Week in Spring, June 5th, 2012

Engineering | Josh Long | June 06, 2012 | ...

Welcome back to another installment of This Week in Spring. As usual, we've got a lot to look at this week so let's get to it..

  1. The video from Chris Beams's recent webinar on the various styles of dependency injection that Spring supports is up. Chris is a core Spring framework engineer (and all around good guy). This video is definitely worth a watch especially if you still think Spring configurations requires XML.
    	  </LI> 
     <LI> Oleg Zhurakousky announced the availability of 
    	 <a href = "http://www.springsource.org/node/3569">
    	 Spring Integration 2.1.2 RELEASE and 2.2.0M2</A>. The new releases are filled with many important bug fixes as well as several  
    	
    	 new features.  
    	 </LI>
    	<LI>  Roy Clarkson has announced the availability of <a href= "http://www.springsource.org/spring-android/news/1.0.0-released">Spring Android 1.0.0.RELEASE</A>! The project is an extension of the Spring Framework that aims to simplify the development of native Android applications by providing RESTTemplate support for…

This Week in Spring: May 29th 2012

Engineering | Adam Fitzgerald | May 29, 2012 | ...

Welcome back to another installment of This Week in Spring! As usual, we have a lot to cover, so let's get straight to it!

  1. Chris Beams has announced that the first milestone release towards Spring 3.2 is now available! This release is great!
    	It includes 
    
    	initial support for asynchronous <CODE> @Controller</CODE> methods,
    	early support for JCache-based cache providers,
    	significant performance improvements in autowiring of non-singleton beans,
    	initial delay support for <CODE> @Scheduled</CODE> and <CODE> &lt;task:scheduled&gt;</CODE>,
    	ability to choose between multiple executuors with <CODE>@Async</CODE>,
    	enhanced bean profile selection using the not (<CODE>!</CODE>) operator,  
    	48 bugs fixed, 8 new features and 36 improvements implemented. 
    	
    

    Check out the latest and greatest bits now, and feel free to give feedback!

    When I asked for any items for consideration into this roundup on my Twitter account, one user immediately shot back: "With the Spring 3.2 news, how about a poll on whether the community wants 3.2 M1 to be followed by RC1. It's too good to wait." I agree, this release is

Spring Roo 1.2.2.RELEASE available

Engineering | Alan Stewart | May 28, 2012 | ...

The Spring Roo team is pleased to announce the availability 1.2.2.RELEASE.  This is the second maintenance release for 1.2 and includes fixes for a number of issues and includes support for Spring Framework 3.1.1 and JDK 7.  Roo 1.2.2 also includes the excellent new "tailor" feature provided by our new partner, Accenture.

I hope you enjoy this new release!

Alan

Spring Roo Project Lead

Transactions, Caching and AOP: understanding proxy usage in Spring

Engineering | Michael Isvy | May 23, 2012 | ...

In the Spring framework, many technical features rely on proxy usage. We are going to go in depth on this topic using three examples: Transactions, Caching and Java Configuration.

All the code samples shown in this blog entry are available on my github account.

Transactions

First step: no transaction

The Service class below is not transactional yet. Let’s first look at it as is and then make it become transactional.

@Service
public class AccountServiceImpl  implements AccountService {
 //…

//Not specifying a transaction policy here!
 public void create(Account account) {
 entityManager.persist(account);
 }
}

Since the method “create” is not transactional, it will most likely throw an exception (because this Account object should not…

This Week in Spring - May 22nd, 2012

Engineering | Josh Long | May 22, 2012 | ...

Welcome back to another installment of This Week in Spring. We have a lot of great content this week, as usual!

  1. Rossen Stoyanchev has put up another blog in his series on Spring MVC 3.2 Preview. This latest installment introduces a Spring MVC chat example.
  2. Oliver Gierke has announced the 1.1.0 GA version of Spring Data JPA. Spring Data JPA makes it very simple to build JPA-based repositories, saving you from the tedious boiler plate code. This new release includes new keywords for query generation (LessThanEqual, GreaterThanEqual, Before, After, StartsWith, EndsWith, and Contains), a handy PersistenceUnitPostProcessor to scan for JPA entities (to be used in Spring versions before 3.1), support for native queries in @Query, and support for declarative locking.
  3. Jonathan Brisbin announced the 1.0.0.M2 release of Spring Data REST. Spring Data REST let's you easily export your Spring repository objects as RESTful endpoints. The new release includes support for invoking query methods of Repository interfaces, support for JSR 303 and Spring Validator validations, and improved support for Spring ApplicationEvents that are emitted before and after each save or delete, and annotation-based configuration.
  4. Oleg Zhurakousky has announced the first milestone release of Spring Integration 2.2. This release includes dependency upgrades, JPA support, and support for "publisher confirms and returns," which are newly supported in Spring AMQP.
  5. Gary Russell has announced version 1.1.0 of Spring AMQP that includes support for the RabbitMQ 2.8.x client, which in turn supports mirrored queues, broker failover, publisher confirms, returns, federated exchanges, and much more.
  6. Matt Vickery has a great post introducing the Spring Integration splitter-aggregator pattern.
  7. Willie Wheeler has a great post up on his custom configuration management database (a CMDB). The post details the project, and then talks about his use of Spring Data's repositories in rebuilding the backend for CMDB. Nice post, Willie!
  8. Doug Haber put together a wonderful post on handling paging using Spring Data and the REST support in Spring 3.1.
  9. Blogger panbhatt has a detailed post on using Spring MVC's REST support to solve a particular set of problems he was having.
  10. Blogger OBSERWATORZY described his particular thought process when trying to consume a RESTful service, and wondering if Spring provided an answer (of course it did!). Read on for his resolution.
  11. Vishal Biyani has put together a nice introduction to getting started with Spring Roo and Cloud Foundry.
  12. The RabbitMQ blog has an amazing article introducing queueing theory (with an introduction to throughput, latency and bandwidth.
  13. JAXEnter has a nice roundup of some of the news releases described in this very post, including the Spring AMQP and Spring Data JPA's GAs.

This Week in Spring, May 15th, 2012

Engineering | Josh Long | May 16, 2012 | ...

Welcome back to another installment of This week in Spring!. We've got a lot to cover this week, as usual. So, onward!

  1. Rossen Stoyanchev has just released part two and three of his blog series introducing Spring MVC 3.2's new features. In the first installment, Rossen introduces how to make a Spring MVC @Controller asynchronous. In the second post, Rossen introduces how to add long polling to an existing web application. Long polling is useful in any number of scenarios where you want to simulate server-side push with client-side applications.
  2. <LI>  The video for <a href= "http://blog.springsource.org/author/ozhurakousky/">Oleg Zhurakousky</A>'s followup webinar introducing <a href ="http://www.springsource.org/node/3550">More Practical Tips and Tricks with Spring Integration</A> has just been posted. Check it out! </LI> 
     <LI> <A href ="http://blog.springsource.org/author/rclarkson/">Roy Clarkson</A>  just announced that <a href = "http://www.springsource.org/spring-mobile/news/1.0.0-released">Spring Mobile 1.0.0 has  been released</A>!  </LI>
    
    
    
    <LI>  SpringSource and Cloud Foundry rockstar  <a  href  ="http://blog.springsource…

Spring MVC 3.2 Preview: Chat Sample

Engineering | Rossen Stoyanchev | May 16, 2012 | ...

Last updated on November 5th, 2012 (Spring MVC 3.2 RC1)

In previous blog posts I introduced the Servlet 3 based async capability in Spring MVC 3.2 and used the spring-mvc-showcase and the Spring AMQP stocks sample to demonstrate it. This post presents a chat sample where the external events are not AMQP messages but rather HTTP POST requests with chat messages. In the second part of the post, I'll switch to a distributed chat where the events are Redis notifications.

Chat is not a common requirement for web applications. However it is a good example of a requirement that can only be met with real-time notifications. It is more sensitive to time delays than email or status alerts and it is not that uncommon to chat in a browser with a friend, or with a colleague during a webinar, or with a live person on a shopping site. You can imagine other types of online collaboration.

The Sample

The spring-mvc-chat sample is available on Github. Although not the focus of this blog post, the client side uses Thymeleaf, knockout.js, and jQuery. Thymeleaf is an excellent alternative to JSPs that enables clean HTML templates with support for previews allowing a designer to double-click an HTML template and view it unlike a JSP that requires a Servlet container. knockout.js is a client-side MVC framework that's very handy for attaching behavior to HTML elements. To get an idea about it quickly, follow one of its excellent tutorials. jQuery is used for DOM scripting and Ajax requests.

ChatController

The ChatController exposes operations to get and post chat message. Here is the method to get messages:


@RequestMapping(method=RequestMethod.GET)
@ResponseBody
public DeferredResult<List<String>> getMessages(@RequestParam int messageIndex) {

  final DeferredResult<List<String>> deferredResult = new DeferredResult<List<String>>(null, Collections.emptyList());
  this.chatRequests.put(deferredResult, messageIndex);

  deferredResult.onCompletion(new Runnable() {
    @Override
    public void run() {
      chatRequests.remove(deferredResult);
    }
  });

  List<String> messages = this.chatRepository.getMessages…

Spring MVC 3.2 Preview: Adding Long Polling to an Existing Web Application

Engineering | Rossen Stoyanchev | May 14, 2012 | ...

Last updated on November 5th, 2012 (Spring MVC 3.2 RC1)

In my last post I discussed how to make a Spring MVC controller method asynchronous by returning a Callable which is then invoked in a separate thread by Spring MVC.

But what if async processing depended on receiving some external event in a thread not known to Spring MVC -- e.g. receiving a JMS message, an AMQP message, a Redis pub-sub notification, a Spring Integration event, and so on? I'll explore this scenario by modifying an existing sample from the Spring AMQP project.

The Sample

Spring AMQP has a stock trading sample where a QuoteController sends trade execution messages via Spring AMQP's RabbitTemplate and receives trade confirmation and price quote messages via Spring AMQP's RabbitMQ listener container in message-driven POJO style.

In the browser, the sample uses polling to display price quotes. For trades, the initial request submits the trade and a confirmation id is returned that is then used to poll for the final confirmation. I've updated the sample to take advantage of the Spring 3.2 Servlet 3 async support. The master branch has the code before and the spring-mvc-async branch has the code after the change. The images below show the effect on the frequency of price quote requests (using the Chrome developer tools):

Before the change: traditional polling

After the change: long poll

As you can see with regular polling new requests are sent very frequently (milliseconds apart) while with long polling, requests can be 5, 10, 20, or more seconds apart -- a significant reduction in the total number of requests without the loss of latency, i.e. the amount of time before a new price quote appears in the browser.

Getting Quotes

So what changes were required? From a client perspective traditional polling and long polling are indistinguishable so the HTML and JavaScript did not change. From a server perspective requests must be held up until new quotes arrive. This is how the controller processes a request for quotes:



// Class field
private Map<String, DeferredResult> suspendedTradeRequests = new ConcurrentHashMap<String, DeferredResult>();

...

@RequestMapping("/quotes")
@ResponseBody
public DeferredResult<List<Quote>> quotes(@RequestParam(required = false) Long timestamp) {

  final DeferredResult<List<Quote>> result = new DeferredResult<List<Quote>>(null, Collections.emptyList());
  this.quoteRequests.put(result, timestamp);

  result.onCompletion(new Runnable() {
    public void run() {
      quoteRequests…

Get the Spring newsletter

Stay connected with the Spring newsletter

Subscribe

Get ahead

VMware offers training and certification to turbo-charge your progress.

Learn more

Get support

Tanzu Spring offers support and binaries for OpenJDK™, Spring, and Apache Tomcat® in one simple subscription.

Learn more

Upcoming events

Check out all the upcoming events in the Spring community.

View all