Jazoon 2013 – Spring Framework 4.0 – The Next Generation

24. October, 2013

Jazoon 2013 badgeIn his talk “Spring Framework 4.0 – The Next Generation,” Sam Brannen gave an overview of the new features of Spring 4.0 (slides on slideshare).

Spring, which has moved to http://spring.io/, is going to version 4 which means they add support for Java SE 8 and Java EE 7.

As a Spring developer, this means better Groovy support, being able to use lambda expressions and method references in Spring callbacks, support for “JSR-310 Date-Time types for data binding & formatting, a new @Conditional mechanism for bean definitions, & a new WebSocket endpoint model.”

Things that I took home from this talk:

  • Spring Boot is a new project to make it easier to set up “Spring-powered, production-grade applications and services with absolute minimum fuss.”
  • @Lazy is now supported to annotate the place where a bean is injected (formerly, you could only use it to make it lazy at the definition)
  • There is a new API for messaging with support for WebSockets. In this context, you may want to have a look at stomp “the Simple (or Streaming) Text Orientated Messaging Protocol.”.
  • Spring 4 supports Java EE 6 through 7 and SE 6 through 8
  • Repeatable annotations will make code more compact

The slides should appear soon on slideshare/sbrannen.


Jazoon 2012: Spring Data JPA – Repositories done right

4. July, 2012

Oliver Gierke presented “Spring Data JPA – Repositories done right” at the Jazoon. The motto of Spring Data could be “deleted code doesn’t contain bugs.” From the web site:

Spring Data makes it easier to build Spring-powered applications that use new data access technologies such as non-relational databases, map-reduce frameworks, and cloud based data services as well as provide improved support for relational database technologies.

Spring Data is an umbrella open source project which contains many subprojects that are specific to a given database. The projects are developed by working together with many of the companies and developers that are behind these exciting technologies.

When you use any form of JPA, you will eventually end up with DAOs which contain many boring methods: getById(), getByName(), getByWhatever(), save(), delete(). How do you like this implementation:

interface MyBaseRepository<T, ID extends Serializable> extends Repository<T, ID> {
  T findOne(ID id);
  T save(T entity);
}

interface UserRepository extends MyBaseRepository {
  User findByEmailAddress(EmailAddress emailAddress);
}

“Wait a minute,” I can hear you think, “these are just interfaces. Where is the implementation?”

That is the implementation. You can now inject those interfaces as DAOs and call the methods. Behind the scenes, Spring will generate a proxy for you that actually implements the methods. 0 lines of code for you to write for 95% of the basic DAO methods.

The queries can even be more complex:

List findByEmailAddressAndLastname(EmailAddress emailAddress, String lastname);

The method will generate SQL that searches by those two columns. See the documentation for more examples how you can write queries that use joins.

On top of that, they built a REST exporter which exposes your DAO interfaces with a REST API to a web browser plus a web front end to explore the repository, to run the queries and to create new objects. Impressive.


Jazzon 2011, Day 3 – Spring 3.1 in a Nutshell – Sam Brannen

26. June, 2011

Spring 3.1 in a Nutshell – Sam Brannen

Sam gave an overview of Spring 3.1. If you don’t like XML, this one is for you.

Along with Servlet 3.0, it’s possible to write web apps that need no XML (not even web.xml).

Profiles and environments allow to use the same code in test and production. There are more concise ways to replace properties in your config. The MVC API has learned a couple of new tricks. Good stuff and probably not too far off.