This Week in Spring - April 23rd, 2013

Engineering | Josh Long | April 23, 2013 | ...

Welcome back to another installment of This Week in Spring! Here in San Francisco, we're experiencing the first fits of life and beautiful weather typical of spring time. Fitting, too, as things are busy-as-can-be in the Pivotal open source communities - including Cloud Foundry and SpringSource - as we march towards the Pivotal Initiative launch on April 24th. See you then!

Without further ado, let's get into this week's roundup:

  1. Have you guys seen the amazing Java configuration support in Spring Batch 2.2.0.RC1? The code I've just linked you to demonstrates a complete working Spring Batch job that reads in a .csv file and then writes the records to a data source, all of which are configured in the class, entirely in Java. This demonstrates the @EnableBatchProcessing annotation in 2.2.0. Check it out!
  2. New SpringOne2GX replays now available in HD on YouTube: Implementing Domain Driven Design with Spring and vFabric, Batch Processing and Integration on Cloud Foundry and a bonus session, Understanding Java Garbage Collection and what you can do about it.
  3. The FuzzyDB open source project tweeted that they'd released a new version of FuzzyDB with Spring Data bindings aligned with the Spring Data Arora release train. Congratulations, guys!
  4. Have you had a chance to play with Thymeleaf, the HTML5 and Spring MVC-friendly templating engine? If you'd like to learn even more, you'll probably like this presentation called Thymeleaf, Will it Blend?
  5. David Welch put together a quick demo of Spring Data Mongo and made the work available. He tweets that he went from working demo in 8 minutes with 4 classes and a pom.xml. Nice work man!
  6. Check out Ramnivas Laddad's awesome talk CloudFoundry Architecture talk at SpringOne2GX up live on the SpringSource YouTube channel SpringSourceDev.
  7. Spring HATEOAS lead Oliver Gierke tweeted a link to this post, "How I Explained REST to my wife", which would seem at first to be just one person's attempt at explaining a fairly deep technology concept to a person who didn't have the same technical background, but quickly turns into a (I think really insightful) look at the applicability of REST. Check out Spring HATEOAS if you want to take your REST-fu to the next level.
  8. I'm personally enamored of the new Java configuration APIs, both those recently released and those currently available in preview releases. I showed a very simple example of the Spring Batch API above. I also took a moment last week to write about the powerful Spring Social Java configuration API soon to be available in the 1.1.0.M2 release.
  9. You can have Spring perform a sort of pre-condition check by using the @Required annotation to insist at runtime that a property be satisfied with a non-null value, or Spring will abort the construction of the object. This helps avoid any silent NullPointerExceptions. This JavaBeat post does a nice job explaining how to use @Required.
  10. The how to do in java blog has a nice posting on how to create a custom UserDetailsService in Spring Security 3.
  11. The JavaCodeGeeks blog has a nice post on how to create RESTful services with Spring MVC.
  12. Brian's Java Blog has a nice post on using Spring AOP with both annotation and XML-centric configuration options.

Introducing Spring XD

Engineering | Mark Fisher | April 23, 2013 | ...

Today we are officially kicking off a new initiative called Spring XD whose theme is "tackling Big Data complexity"1.

The Spring Data team has been incredibly busy over the past few years, not only providing support for NoSQL datastores but also simplifying the development experience with Hadoop. With the creation of the Spring for Apache Hadoop project, we made it easier to get started developing Hadoop applications by providing a rich configuration model and a consistent programming model across Hadoop ecosystem projects such as Hive and Pig. As Spring users would expect, one can:

  1. Configure and run MapReduce jobs as container managed objects.
  2. Use template helper classes for HDFS, HBase, Pig and Hive to remove boilerplate code from your applications.

Spring…

This Week in Spring - April 16th, 2013

Engineering | Josh Long | April 16, 2013 | ...

Welcome to another installment of This Week in Spring! It's been an exciting week for Spring at Pivotal, which you can hear more about at the re-scheduled Pivotal launch event on April 24th.

  1. In case you are reading too fast, Pivotal has re-scheduled the launch event to April 24th. Register here!
  2. Arjen Poutsma has announced Spring Web Services 2.1.3.RELEASE. The new release mainly consists of bug fixes, for the full details check out the changelog.
  3. Don't miss the upcoming Webinar with Donald Miner and Mark Pollack discussing Pivotal HD and Spring Hadoop, a good introductory webinar for those that are Pivotal HD-curious.
  4. New SpringOne2GX replays now available in HD on YouTube: Cloud Foundry Architecture, Effective Design Patterns in NewSQL
  5. There was a great post on Reddit the other day that explains the difference between REST and SOAP in terms of Martin Lawrence. This has nothing to do with Spring, but was droll enough that it's worth sharing.
      Spring, of course, has an amazing REST stack and I highly encourage people to check out how to build consolidated, streamlined REST services with Spring! Moving on... :) 
    
  6. James Rossiter has a good post on how to use a Spring InitBinder to Resolve Type Mismatch and bind Exceptions in POST from Spring MVC to Controller Actions.
  7. @olivergierke brings up a great point on Twitter: how much code does it take to add the JTA 1.2 JSR javax.transaction.Transactional annotation to Spring? Almost nothing! Most of the code here is just unit tests. Otherwise, this is just a dead simple mapping of the JTA annotation to Spring's already supported engine, which also currently supports the native Spring @Transactional and @javax.ejb.TransactionAttribute annotation.
  8. Are you looking into Gradle and want to get started with Spring, quickly? Giancarlo Frison has put together a nice post with a bootstrap Gradle build that can be used with Spring applications.
  9. Eugen Paraschiv has put together a nice post on how to use RestTemplate to do HTTP BASIC authentication.
  10. Spring has long supported a utility class, called the org.springframework.util.StopWatch, which can be used to measure the execution of method invocations. The Javarevisited blog has a
      <a href="http://www.stumbleupon.com/su/1rKtfP/javarevisited.blogspot.com.au/2012/04/how-to-measure-elapsed-execution-time.html">nice post on how to use the <CODE>StopWatch</code> class</a>.
    </LI>
    
  11. This post is fairly old, but I just stumbled upon it and thought it was a well thought out presentation introducing Aspect Oriented Programming (AOP) in Spring.

This Week in Spring - April 9th, 2013

Engineering | Josh Long | April 09, 2013 | ...

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

  1. SpringSource CTO Adrian Colyer outlines the direction and momentum of SpringSource and the Spring projects under the Pivotal Initiative, a new company spun out of EMC comprised of - among other things - SpringSource, Cloud Foundry, and GreenPlum. This is definitely worth a read if you want to understand Spring's - ahem - Pivotal role in this new initiative!
    </LI>  
    <LI> Spring Batch lead Michael Minella has <A href="http://www.springsource.org/node/9666"> announced that Spring Batch 2.2.0.RC1 is now available</a>.
    	The new release includes preliminary support for Spring Data, Java configuration support, non-identifying job parameters 
    	and numerous fixes and polishes. This release is amazing, and definitely worth a look. I, personally, <EM>love</EM> the Java configuration API that's
    	been surfaced. You don't need to write another…

Spring and Open Source at the Pivotal Initiative

Engineering | Adrian Colyer | April 03, 2013 | ...

By now you’ve probably heard about Pivotal. I’d like to take a moment here to explain what this means for Spring, and to tell you about some of our plans for 2013.

In case you missed it, here’s the essential background on Pivotal: Led by Paul Maritz, the initiative unites key people and projects from across EMC and VMware to bring “consumer grade” technology to the enterprise. We see a new generation of applications emerging that are powered by new data fabrics and will interact with and serve customers in the context of who they are, where they are, and what they are doing in the moment…

This Week in Spring - April 2nd, 2013

Engineering | Josh Long | April 02, 2013 | ...

Welcome to another installment of This Week in Spring ! I've just returned from Devoxx UK and Devoxx France where I was very happy to talk to developers using Spring from all walks of industry. I also spoke at Skills Matter in London on building web applications using Spring. Thanks to Skills Matter, the London Spring User Group, and to the amazing Rob Harrop for having me, it was such a pleasure! The video from that session is available online if you're interested.

  1. Register today for the Super Early Bird rate at SpringOne 2GX 2013, in Santa Clara, CA Sept 9th-12th, 2013!
  2. Gary Russell's announced that Spring AMQP 1.2.0.M1 is now available.
  3. <LI> The Cujojs team has announced that <CODE>rest.js</CODE> is <a href="http://cujojs.com/">now part of Cujo.js</a>
    <a href…

This Week in Spring - March 26, 2013

Engineering | Josh Long | March 26, 2013 | ...

Welcome to another installment of This Week in Spring! This week I'm in chilly (brrr!) London, England and Paris, France, for Devoxx UK and Devoxx FR and - tonight - I gave a talk at Skills Matter for the London Spring User Group. What a pleasant experience. If you're in France and want to talk Spring, don't hesitate to ping me.

  1. The CujoJS team has announced that When.js 2.0 is now available.
  2. I found a few nice posts introducing Spring Integration. Here's part 1 and part 2.
     These posts are very thorough and well worth a read! </LI>
     <LI>New SpringOne2GX replays now available in HD on YouTube: <a href="http://www.springsource.org/node/4302">What's New in Spring Integration 2.2 and Spring Integration, Batch, &amp; Data Lightning Talks</a>.</LI>
     <LI> Did you guys miss SpringOne2GX 2012? Don't fret, Oleg Zhurakousky and Arjen Poutsma's talk introducing <a href="http://t.co/nquWxe7L3u">how to use Spring with Scala is now available on InfoQ</a>. </LI>
     <LI>Michael Isvy's been hard at work refactoring the code 
    	 of the canonical Spring PetClinic reference…

Spring Petclinic is on Github!

Engineering | Michael Isvy | March 21, 2013 | ...

We are pleased to announce that the Spring Petclinic sample application has been refactored.

The source code is now available on github. Here is a screenshot of the new application:

And here is an overview of the new architecture:

Spring, Spring, Spring

We have used the following Spring features:

  • Dependency Injection using Annotations
  • Data Access Integration using jdbc (JdbcTemplate), JPA or Spring Data JPA (repository layer). You can choose which implementation to use by setting up the corresponding bean profile in web.xml or in one of the JUnit tests.
  • Transactions using @Transactional (service layer)
  • Caching using @Cacheable with ehcache as a cache implementation (service layer)
  • Aspect Oriented Programming (to monitor how many times has been called each of the Repository methods)
  • Spring MVC: Form validation using Bean Validation (JSR-303)
  • Spring MVC: content negotiation (html, xml or atom) using ContentNegotiatingViewResolver.
  • Spring MVC: exception handling using SimpleMappingExceptionResolver
  • Spring MVC: use of the Spring MVC Test Framework

 

Our Vibrant Community

We have had quite a lot of contributions from experts in our community (including the leads of several open source projects).

 

Thymeleaf

In case you haven’t heard of it yet, Thymeleaf can be seen as a replacement for JSP. it defines itself as an  XML / XHTML / HTML5 template engine.

It is based on some plain HTML files with a little bit of namespace magic.

Daniel and Soraya from the Thymeleaf project have created a Spring-Petclinic branch that uses Thymeleaf instead of JSP. They have documented the migration steps in this blog entry: http://www.thymeleaf.org/petclinic.html

The Thymeleaf branch of Spring Petclinic is available here: https://github.com/thymeleaf/thymeleafexamples-petclinic

To learn more about Thymeleaf: http://www.thymeleaf.org

To follow Thymeleaf on twitter: https://twitter.com/thymeleaf

 

Dandelion

Dandelion provides a set of taglibs that you can use with JSP or Thymeleaf.

We have used it inside Spring-Petclinic to work with DataTables. It generates tables based on jQuery DataTables and Bootstrap.

You can do things like that:


<datatables:table data="${ownerList}" id="dataTable"  theme="bootstrap2" export="pdf">
 <datatables:column title="Name" property="name" sortable="true" />
 <datatables:column title="Address" property="address" sortable="true" />
</datatables:table>

The output html table then looks like this:

Dandelion is used inside the main branch of Spring Petclinic.

Thibault Duchateau from the Dandelion project has written a nice blog entry that describes the migration of the Spring Petclinic application

To learn more about Dandelion:  http://dandelion.github.com/

To follow them on twitter: https://twitter.com/dandelion_proj

 

Maven or Gradle?

By default, Spring Petclinic uses Maven as it is the most common choice for Java applications. While Spring Petclinic is fairly small in comparison to most real-life applications, its Maven pom.xml file is pretty verbose already.

Li Yanhui from Thoughtworks China has been nice enough to migrate Spring Petclinic to Gradle. That is a great way to compare Maven and Gradle side by side. The build.gradle configuration file is indeed much simpler to understand. It currently contains 143 lines (as opposed to 543 lines for the Maven POM).

You can browse the Gradle-based version of Spring Petclinic here: https://github.com/whimet/spring-petclinic Thanks to them we have been able to identify a few places inside Spring Petclinic that contained code duplication and lacked of automated testing.

 

Performance Testing: Let’s Scale!

Would it be possible to take Spring Petclinic as it is now and scale it up to 1000 requests per second on a single server instance? Julien Dubois from Ippon Technologies has written a great series of five blog entries on that topic.

It answers questions such as: - Should I rely on the session context? (part 2) - Which Apache Tomcat connector should I use? (part 2) - Which database connection pool should I use? (part 3) - Is JDBC faster than JPA or Spring Data JPA? ( part 4) - What are the pros of using OpenSessionInViewFilter? ( part 4)

 

References

Spring Petclinic on GitHub Spring Petclinic on Cloud Foundry Petclinic + Thymeleaf Petclinic + Gradle

 

Spring Data GemFire 1.3.0 Released

Engineering | David Turanski | March 14, 2013 | ...

I am pleased to announce the GA release of Spring Data GemFire 1.3.0. In addition to many minor bug fixes and enhancements, this release includes some notable new features to make writing Java applications with GemFire even easier:

Annotation Support For Functions

GemFire provides the ability to "bring the code to the data" by providing a framework for remote function execution. In keeping with Spring's core values, Spring Data GemFire hides the boilerplate code necessary to register and execute remote functions, allowing you to write POJOs and focus on application logic. See the Annotation Support for Function Execution chapter in the Spring Data GemFire Reference Guide for details.

Simplified Connection to a GemFire Datasource

GemFire exposes a lot of options for tuning the performance of it's connection pool, and to configure how local data is managed an synchronized. The Spring Data GemFire namespace supports all of these options, however many applications are clients that simply need read/write access to the GemFire data grid. For this class of applications, it is now possible to connect to GemFire as a client without explicitly configuring a pool or client regions:

 <gfe-data:datasource>
        <gfe-data:locator host="${host}" port="${port}"/>
 </gfe-data:datasource>

The above configuration will create a client cache, pool, and proxy client regions for all available regions on the server, with sensible defaults, and register them as Spring beans.

JSON Support

GemFire 7.0 provides the ability to store JSON with full query support. Typically this requires the application to use the JSONFormatter to convert GemFire's internal format to and from JSON Strings. Spring Data GemFire now provides an option to perform this conversion automatically for selected regions, as will as one way conversion from Object to JSON using Jackson's ObjectMapper. This feature uses Spring AOP to intercept appropriate operations on Region and GemFireTemplate. See the Spring Data GemFire Reference Guide for details.

Performance Improvements in STS 3.2.0

Engineering | Martin Lippert | March 12, 2013 | ...

The latest release of the Spring Tool Suite (3.2.0) contains a large number of performance improvements in many different areas. We are not only adopting the latest improvements from the Eclipse Juno SR2 maintenance release (which fixes a large number of performance issues with the new Eclipse 4 platform UI), we also worked on the performance of many of the STS internals, specifically targeting Java editing and build times for Spring projects.

To demonstrate the improvements, here is a quick screencast showing STS 3.1.0 and 3.2.0 side-by-side:

There is still more to do and we will continue to work on these areas for the STS 3.3.0 release, scheduled to arrive in July 2013. If you want to know more details, watch for further improvements, submit additional information, and/or report specific performance or memory issues, please watch/use this JIRA ticket: https://issuetracker.springsource.com/browse/STS-3054

Get the Spring newsletter

Stay connected with the Spring newsletter

Subscribe