The Spring Blog

Engineering
Releases
News and Events

"Bootiful" Java EE Support in Spring Boot 1.2

In this blog, I want to look at - and demonstrate - some of the many new features in Spring Boot 1.2 that make the lives of those coming from, or otherwise building on, Java EE easier.

It's worth mentioning that a lot of this support has been possible with Spring before, of course, but now with Spring Boot 1.2, it's just so darned easy!

First, here's an example program with notes after.

package demo;

import org.glassfish.jersey.jackson.JacksonFeature;
import org.glassfish.jersey.server.ResourceConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.core.JmsTemplate;

import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;
import javax.jms.JMSException;
import javax.persistence.*;
import javax.transaction.Transactional;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.io.Serializable;
import java.util.Collection;
import java.util.logging.Logger;

@SpringBootApplication
public class Application {

    @Named
    public static class JerseyConfig extends ResourceConfig {

        public JerseyConfig() {
            this.register(GreetingEndpoint.class);
            this.register(JacksonFeature.class);
        }
    }

    @Named
    @Transactional
    public static class GreetingService {

        @Inject
        private JmsTemplate jmsTemplate;

        @PersistenceContext
        private EntityManager entityManager;

        public void createGreeting(String name, boolean fail) {
            Greeting greeting = new Greeting(name);
            this.entityManager.persist(greeting);
            this.jmsTemplate.convertAndSend("greetings", greeting);
            if (fail) {
                throw new RuntimeException("simulated error");
            }
        }

        public void createGreeting(String name) {
            this.createGreeting(name, false);
        }

        public Collection<Greeting> findAll() {
            return this.entityManager
                    .createQuery("select g from " + Greeting.class.getName() + " g", Greeting.class)
                    .getResultList();
        }

        public Greeting find(Long id) {
            return this.entityManager.find(Greeting.class, id);
        }
    }

    @Named
    @Path("/hello")
    @Produces({MediaType.APPLICATION_JSON})
    public static class GreetingEndpoint {

        @Inject
        private GreetingService greetingService;

        @POST
        public void post(@QueryParam("name") String name) {
            this.greetingService.createGreeting(name);
        }

        @GET
        @Path("/{id}")
        public Greeting get(@PathParam("id") Long id) {
            return this.greetingService.find(id);
        }
    }

    @Entity
    public static class Greeting implements Serializable {

        @Id
        @GeneratedValue
        private Long id;

        @Override
        public String toString() {
            return "Greeting{" +
                    "id=" + id +
                    ", message='" + message + '\'' +
                    '}';
        }

        private String message;

        public String getMessage() {
            return message;
        }

        public Greeting(String name) {
            this.message = "Hi, " + name + "!";
        }

        Greeting() {
        }
    }

    @Named
    public static class GreetingServiceClient {

        @Inject
        private GreetingService greetingService;

        @PostConstruct
        public void afterPropertiesSet() throws Exception {
            greetingService.createGreeting("Phil");
            greetingService.createGreeting("Dave");
            try {
                greetingService.createGreeting("Josh", true);
            } catch (RuntimeException re) {
                Logger.getLogger(Application.class.getName()).info("caught exception...");
            }
            greetingService.findAll().forEach(System.out::println);
        }
    }

    @Named
    public static class GreetingMessageProcessor {

        @JmsListener(destination = "greetings")
        public void processGreeting(Greeting greeting) throws JMSException {
            System.out.println("received message: " + greeting);
        }
    }

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
Read more...

Spring Boot 1.2.0.RC2 Available Now

I am pleased to announce that the second release candidate for Spring Boot 1.2.0 is available now in the Spring milestone repository. This is mainly a bug fix release, although we did manage to sneak in a fantastic community contribution which adds support for Undertow as an embedded Servlet container.

For a complete list of changes, and for upgrade instructions, see the Spring Boot 1.2 Release Notes on the WIKI. The reference documentation has also been updated to cover new features.

As usual, please report any problems using the project Issue tracker.

Read more...

Spring Roo 1.3.0 introduces JDK 8 support

On behalf of the Spring Roo team, I am pleased to announce the release of Spring Roo 1.3.0, the first version released by DISID Corporation as project lead.

Spring Roo is a rapid application development tool for Java, allowing you to create full web enterprise applications in just minutes.

This is the first time that Spring Roo jar files have been published to Maven Central! As always, the release is available in the Spring IO repository.

The 1.3.0 release includes bug fixes and enhancements as well as several new features:

Read more...

Screencast: How to create a RESTful app in five minutes or less

Recently, a friend of mine tweeted out a challenge:

"Name a framework in which you can create a new app expose a REST service with a database and deploy it to the cloud in five minutes. #grails"

The moment I spotted that tweet, I responded, "Spring Boot + Spring Data REST"! I realized he was kindly pointing out how easy it is to build RESTful services with Grails (a great framework). But I couldn't resist showing the ease and power of Spring Data REST.

To prove my point, I couldn't resisting crafting a screencast. In the linked screencast, I show how über easy Spring has made it to pick the parts for your app from http://start.spring.io, define your domain, and then export them as a hypermedia-driven RESTful service.

Read more...

Spring XD 1.1 M1 and 1.0.2 released

On behalf of the Spring XD team, I am very pleased to announce the first milestone release of Spring XD 1.1 and the 1.0.2 maintenance release.

Download Links:

  • 1.0.2.RELEASE: zip, 1.1.0.M1 RELEASE: zip

In addition to bug fixes, Spring XD 1.0.2 now supports Apache Hadoop 2.5.1. Pivotal PHD 2.1 and Cloudera CDH 5.1.3.

The 1.1 M1 release includes bug fixes and enhancements as well as several new features:

Read more...

This Week in Spring - November 18th, 2014

Welcome to another installment of This Week in Spring! This week I'm in sunny Sofia, Bulgaria for the Java2Days software conference. As usual, this show is way too much fun and the crowd's bigger and better than ever!

  1. Spring Boot 1.2.0 RC1 is now available! This release moves embedded Servlet containers to Tomcat 8 or Jetty 9, adds a new @SpringBootApplication annotation, adds JavaMail support, and registers additional Spring Boot actuator support
  2. Spring Session 1.0.0.RC1 is here with loads of features!
  3. Speaking of using Spring with ZeroTurnaround, join ZeroTurnaround's Adam Koblentz and I on Nov 20th as we look at using JRebel and Spring Boot to deliver a one-two developer productivity punch without equal
  4. Want to learn more about the Reactor project and the role of asych I/O in microservices? Check out the upcoming Reactor webinar!
  5. Spring for Apache #Hadoop 2.1.0M2 is now available!
  6. Andy Wilskinson has just announced that Spring IO Platform 1.0.3 is now available
  7. Another great SpringOne2GX 2014 replay is up: Spring Data ninjas Thomas Darimont, Oliver Gierke, and Christoph Strobl's talk What's new in Spring Data.
  8. Check out the replay of our pal Venkat's talk from SpringOne2GX 2014, Java 8 Language Capabilities, What's in it for you?
  9. Splunk's Damien Dallimore SpringOne2GX 2014 talk, Gaining Application Lifecycle Intelligence, is now available online!
  10. Slideware from SpringOne2GX 2014 is also up! They are linked to from the session details on the http://springone2gx.com website.
  11. Our pal Simon Maple over at ZeroTurnaround just published a nice post, What You Can Build for Free in 2 Hours with Spring Boot, Twitter, and Facebook
  12. Simon also did a nice post that has him basically following the Spring IO guide on building REST services
  13. You listen to the SE Radio podcast, I trust? You should. It's legit. Check out this nice interview with James Lewis, microservice luminary, on what a microservice is. I think it's a pretty darned interesting discussion.
  14. Looking for a more non-trivial Spring and WebSocket sample backed by ActiveMQ? Check out this example
  15. I've been loving the Cloud Foundry After Dark recorded Google Hangout sessions. If you're not following them, this is definitely fun.
  16. I do a techtip for our e-mail newsletter, and we're going to start publishing those techtips on the blog. First up: building a Spring Integration 4.1 websocket integration
Read more...

Spring Session 1.0.0.RC1 Released

I'm pleased to announce the release of Spring Session 1.0.0.RC1.

For full details on the changes made in the release, please refer to the changelog. The highlights of this release include:

Read more...

SpringOne2GX 2014 Replay: Developer Tooling - What’s New and What’s Next

Recorded at SpringOne2GX 2014.

Speakers: Andy Clement, Martin Lippert

Slides: http://www.slideshare.net/SpringCentral/developer-tooling-whats-new-and-whats-next

In this talk we take a look at the latest changes and new features of the Spring Tool Suite, the Eclipse-based IDE that comes packed with support for Spring, Groovy, Grails, Gradle, AspectJ, and Cloud Foundry. We dive into the new ways the tooling makes it easy and convenient to develop enterprise applications that are based on Spring Boot and how the Spring Tool Suite integrates will all the different parts of Spring IO. In addition to that we will show the Java8 language tooling that comes as part of the Spring Tool Suite and demonstrate how to get the most out of Java8 in your projects. In the second part of this presentation we take a look at our vision for how we are going to move developer tooling itself into the cloud era. We provide a sneak peek under the hood of what we are working on for the next generation of developer tooling. We will demonstrate what future cloud-based developer might look like, how real Java language tooling can look and feel when running in a browser-based code editor, and show how every developer can smoothly migrate into this new world of cloud-based developer tooling. All this is based on Flux, a new project at eclipse.org, that aims at providing new and innovative ways to move towards cloud-based tooling in a smooth, seamless way.

Read more...

SpringOne2GX 2014 Replay: Java 8 Language Capabilities, What's in it for you?

Recorded at SpringOne2GX 2014.

Speaker: Venkat Subramaniam

No Slides at speaker request

There is a good amount of excitement about the new version of Java. The big evolution of course is the lambda expressions. In this presentation we will dive into the language features in Java 8, take a look at some of their nuances, and look at ways to put them to good use. In addition to looking at lambdas we will also dive into the Streams capabilities and also some of the features in Java 8 that make all these possible.

Read more...

SpringOne2GX 2014 Replay: What's new in Spring Data?

Recorded at SpringOne2GX 2014.

Speakers: Thomas Darimont, Oliver Gierke, Christoph Strobl

Slides: http://www.slideshare.net/SpringCentral/whats-new-in-spring-data

This talk will give a broad overview of the new features introduced in the latest Spring Data release trains. We will cover recent additions and improvements in Spring Data Commons - the module that's shared amongst the store specific ones. We'll then delve into the latest and greatest features of individual store modules, like JPA, MongoDB, Neo4j, Solr and the community ones as well.

Read more...