BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Spring 4 Enhances Support for Java 8, Java EE 7, REST and HTML5

Spring 4 Enhances Support for Java 8, Java EE 7, REST and HTML5

Lire ce contenu en français

Last Thursday, Pivotal released Spring 4.0, the first major release since 2009. The new release supports Java 8 with expression of callbacks using lambdas, JSR 310 Date and Time API, and parameter name discovery.

Java EE 7 support includes JMS 2.0, JTA 1.2, JPA 2.1, Bean Validation 1.1, and JSR-236 Concurrency utilities.

Spring 4 also features improved REST support with a new AsyncRestTemplate and HTML5/WebSocket integration with fallback for older browsers.

To read more about the comprehensive list of new features and capabilities in Spring 4, see Chief Architect, Application Fabric at Pivotal Adrian Colyer's Announcing the Spring Framework 4.0 GA release.

Spring 4 claims to give both Java and Groovy developers a simpler way to deliver and integrate new application architectures, big data, devops and cloud-friendly deployment. In addition, it includes a new project named Spring Boot. Spring Boot is a new Spring technology that aims to deliver Ruby on Rails-like productivity to Java development.

Spring has many projects under its umbrella. Spring IO was recently created to bring the core Spring APIs into a cohesive and versioned foundational platform. More generally, it's a new website with reference documentation, tutorials, team blog and forum. The Spring 4 press release contains an interesting quote about how Spring IO and Spring Boot help developers:

A major goal of Spring IO is to make Java a leader in developer productivity via components like Spring Boot and Groovy. "The bar for developer happiness and intolerance of boilerplate code has been set very high at Pivotal Labs, which historically has done a lot of Ruby on Rails development," said Edward Hieatt, chief operating officer, Pivotal Labs. "Our Ruby on Rails developers who use Spring Framework 4.0 with Spring Boot are impressed with its productivity and ability to address a wide range of scenarios on a single programming model."

I wanted to see if Spring 4 was a drop-in replacement for Spring 3, so I recently conducted an experiment to find out. In A Webapp Makeover with Spring 4 and Spring Boot, I took an application developed with Spring 3.2.5, Spring Security 3.1.4 and Jersey 1.18 and upgraded it to Spring 4, Jersey 2 and Java 8. Furthemore, I integrated Spring Boot and converted it to JavaConfig instead of XML. The development experience was pleasant. I found that Spring, once again, has excellent backwards compatibility. The only issues I found were with Jersey in a container-less environment.

Following the release announcement, I had a chance to talk with Adrian Colyer.

When you say Spring 4.0 has deep support for Java 8, what do you mean? Why is Java 8 easier with Spring?

Java 8 is a perfect fit for Spring's programming model. We believe that the combination is very attractive, with Java 8 offering elegant language features and library improvements for immediate use with typical Spring APIs. In fact, Spring Framework 4.0 is the first fully Java 8 enabled application framework in the industry. We went the extra mile to provide everything that is necessary to start developing Spring applications on Java 8 today, even before the production launch of Java 8 in March.

You say that Spring Boot delivers unprecedented productivity to Java. What about Grails, Spring Roo, Play and JRebel? They allow you to develop all day long without restarting your app. How is Spring Boot better than those technologies?

Boot delivers productivity more to "enterprise" Java, and covers a much broader set of applications from web, to batch to purely data applications (see Spring XD). Grails on the other hand is very focused on rapid application development of web applications in a full stack environment. Spring addresses far more than just web apps, and Boot represents a convention-over-configuration approach for Spring and it's ecosystem projects. Well, ok, we don't offer Boot support yet for every last Spring project, but the pace of adoption is *staggering* and it won't be long until 100% saturation.

Why does Pivotal have so many JVM-based frameworks (Grails, Spring Roo and now Spring Boot) for creating new applications?

As a matter of fact, all Pivotal JVM-based frameworks (Boot, Grails and Roo) are based on Spring MVC, but cater to distinct audiences. Boot provides an opinionated, convention over configuration style for the Spring ecosystem, which is much broader than just web applications. Grails on the other hand is a very focused domain specific runtime targeted at the rapid development of web applications using the Groovy language and DSLs. Finally, Roo is focused purely on code generation. All of these frameworks bring developers to the Spring platform, which is our main focus.

Do you believe that more choices causes anxiety for developers and decision makers?

Tricky/subjective question to answer. To decision makers, more choices likely sounds like better risk management, easier hiring and developer on-boarding. To developers, it's likely more anxiety provoking, relatively speaking, until they discover the existence of a style that speaks to better their background and skill level exists -- then they get excited.

Spring-Loaded seems like a free version of JRebel. According to its website, it's the reloading system used in Grails 2. Is this project at all related to Spring Boot and its unprecedented productivity?

No. Boot is enabled in Spring Framework 4.0 by the @Conditional annotation infrastructure. Your perception of loaded is accurate otherwise - JRebel is much more comprehensive, works with multiple IDEs, etc.

What does Spring 4's WebSocket support provide that is missing from Java EE (or other implementations)?

It's about fallback options (SockJS) and higher-level messaging protocols (STOMP). We consider WebSocket primarily as a transport layer; the really interesting parts emerge on top of it. Spring's new messaging module indicates where we see the common ground for application developers. This goes far beyond what JSR-356 does in Java EE 7; note that we do support JSR-356 as a foundation but rather focus on the higher-level interaction patterns in our own WebSocket programming model. Since WebSocket is not supported in Internet Explorer < 10, WebSocket alone is not practically usable today without fallback options.

Besides support for WebSockets and HTML5 attributes in Spring's JSP Tags, what other features does Spring 4 offer for HTML5?

Our focus is on enabling HTML5-oriented web application architectures. From our perspective, this is more about communication styles and state management arrangements than it is about specific HTML5 features. That said, Spring is also a good citizen with respect to popular JavaScript frameworks on the client side. And we are not just doing our share there at the moment, we are also committed to ongoing evolution towards those next-generation web architectures in the Spring 4.x line.

In my experience (from consulting and speaking at conferences), most developers are still using Spring with XML. Do you think more developers will shift to JavaConfig with Spring 4?

It's their choice, they can adopt when and where it makes sense for them. They can use annotations, JavaConfig, or XML - which is more options than Java EE offers. By the way, we love JavaConfig, and hope that more organizations are able to adopt it.

If you're using Spring with Maven, there's a new "bill of materials" POM that you can use to upgrade. To download or view Gradle coordinates, see the Spring Framework project website.

Rate this Article

Adoption
Style

BT