The Spring Blog

Engineering
Releases
News and Events

This Week in Spring - December 6th, 2016

Welcome to another installment of This Week in Spring! This week I’m in Brisbane, Australia, on the second leg of the YOW! conference circuit. If you’re around, please say hi or find me when YOW! moves to Sydney in a few days.

We’ve got a lot to cover so let’s get to it!

Read more...

This Week in Spring - November 29th, 2016

Welcome to another installment of This Week in Spring! I can’t believe how quickly this year has gone! This week I’m in Melbourne, Australia for the YOW! conference and then week it’s off to Brisbane and then Sydney for the next editions of the same show. Australia is the furthest I’ve ever been from my ‘native’ timezone - so even though I always post This Week in Spring every Tuesday, I appreciate that it’s still Monday for anybody west of Europe right now! Tonight, I’ll join my pal, Intellij’s Trisha Gee, and we’ll be speaking at the Melbourne JVM User Group. I’m super excited to be here, for my first time, helping bring the Spring down under. If you’re around then say hi (@starbuxman)!

Read more...

Going reactive with Spring Data

Last weeks' Spring Data Kay M1 is the first release ever that comes with support for reactive data access. Its initial set of supported stores — MongoDB, Apache Cassandra and Redis — all ship reactive drivers already, which made them very natural candidates for such a prototype. Let’s take a more detailed look at the new programming model and the APIs that make up that support.

Reactive Repositories

The repositories programming model is the most high-level abstraction Spring Data users usually deal with. They’re usually comprised of a set of CRUD methods defined in a Spring Data provided interface and domain-specific query methods. Here’s what a reactive Spring Data repository definition would look like:

public interface ReactivePersonRepository
  extends ReactiveCrudRepository<Person, String> {

  Flux<Person> findByLastname(Mono<String> lastname);

  @Query("{ 'firstname': ?0, 'lastname': ?1}")
  Mono<Person> findByFirstnameAndLastname(String firstname, String lastname);
}

As you can see, there’s not too much difference to what you’re used to. However, in contrast to the traditional repository interfaces, a reactive repository uses reactive types as return types and can do so for parameter types, too. The CRUD methods in the newly introduced ReactiveCrudRepository, of course make use of these types, too.

By default, reactive repositories use Project Reactor types but other reactive libraries can also be used. We provide a custom repository base interface (e.g. RxJava2CrudRepository) for those and also automatically adapt the types as needed for query methods, e.g RxJava’s Observable and Single. The rest basically stays the same. Note, however, that the current milestone does not support pagination yet and you of course have to have the necessary reactive libraries on the classpath to activate support for a particular library.

Activating reactive Spring Data

Similarly to what we have in the blocking world, the support for reactive Spring Data is activated through an @Enable… annotation alongside some infrastructure setup:

@EnableReactiveMongoRepositories
public class AppConfig extends AbstractReactiveMongoConfiguration {

  @Bean
  public MongoClient mongoClient() {
    return MongoClients.create();
  }

  @Override
  protected String getDatabaseName() {
    return "reactive";
  }
}

See how we use a different base class for the infrastructure configuration, as we need to make use of the MongoDB async driver.

Read more...

This Week in Spring - November 21st, 2016

Welcome to another installment of This Week in Spring! This week I’m.. home! It’s Thanksgiving this week here in the states, after all. I am sure that I speak for the entire Pivotal team when I say that we are grateful for you, the most wonderful community on the planet. Thanks so much, and if you’re celebrating Thanksgiving, then happy Thanksgiving to you! When you’re finished with your meal - barely able to keep an eye open - I hope you’ll find a comfy arm chair and take in some of the content in this week’s roundup.

Read more...

The Joy of Mustache: Server Side Templates for the JVM

I don’t do much server-side templating, but when I do…​ well frankly, I tend to forget things. Every template language has its strengths and weaknesses, and they all have syntax to remember, and more frequently to forget. Recently I completed some work on the old Spring Petclinic, converting it to use Thymeleaf in the view layer, and re-organizing the code to be a bit more "modern". I enjoyed working with Thymeleaf 3, and found it a pleasant experience, but had to spend a lot of time scanning documentation and samples. Then I had another little project that needed some templates, and I remembered my fondness for Mustache, which we added to Spring Boot back in version 1.2, and which plays an important role in the excellent Spring REST Docs tool. I added spring-boot-starter-mustache to my new project, and was up and running within seconds.

Read more...

This Week in Spring - November 15th, 2016

Welcome to another installment of This Week in Spring! Time sure is flying! We’ve got so much to get into this week. Can you believe we’re staring down 2017? We’ve got so much to cover so let’s get to it!

Read more...

Vaadin Spring 1.1 - build web UIs that hook right to your Java backend

This post is a guest post by community member Matti Tahvonen (@MattiTahvonen), who works as a developer advocate in Vaadin Ltd, the company that originally developed Vaadin Framework and provides commercial services and extensions for it.

The first stable release of the official Spring integration library for Vaadin was released a bit over a year ago. The feedback has been great and many Spring developers, who have wanted to stay on the safe “backend side”, have discovered a new way to use their existing Java skills to build good-looking web UIs. Using Vaadin Spring, your UI code lives in Spring managed beans and the integration with your Spring based backend becomes trivial.

Read more...