Spring Team
Josh Long

Josh Long

Spring Developer Advocate

an aisle seat or San Francisco, CA

Josh Long is the Spring Developer Advocate. Josh is the lead author on Apress’ Spring Recipes, 2nd Edition, the O'Reilly "Pro Spring Roo" book, the Pearson "Livelessons for Spring" and a committer on several Spring projects and the Activiti BPMN framework. When he’s not hacking on code, he can be found at the local Java User Group or at the local coffee shop. Josh likes solutions that push the boundaries of the technologies that enable them. Josh's interests include big-data, mobile, REST, NoSQL and integration. He blogs on the Spring blog and [on his personal blog](http://joshlong.com).
Blog Posts by Josh Long

This Week in Spring - December 16th, 2014

Welcome to another installment of This Week in Spring! In a few short weeks we’ll be in 2015! Will that be exciting? Of course. But this week’s pretty exciting as well! So much good stuff this week.

Read more...

This Week in Spring - December 9th, 2014

Welcome to another installment of This Week in Spring! In a few short weeks we’ll be in 2015! Will that be exciting? Of course. But this week’s pretty exciting as well! So much good stuff this week.

Read more...

This Week in Spring - December 2, 2014

Welcome to another installment of This Week in Spring! This week I'm at the Rich Web Experience in Ft. Lauderdale, FL, joining my pal Matt Stine for a workshop on building microservices with Spring Boot, Spring Cloud and Cloud Foundry.

So, without further ado, let's get to it:

Read more...

This Week in Spring - November 25th, 2014

Egads! Can you believe it's already almost the end of the year? Time has been screaming fast! It's the week of Thanksgiving for those of us in the United States. This is a wonderful time of year to sit back, find a nice Spring IO guide or blog to read, and then build something awesome.. oh, and it's an ideal time to spend in the company of friends and family and to reflect on those and that for which we're grateful. I'm sure I speak for the Spring team and Pivotal at large when I say that we're grateful for you, our inspiring community, users and customers.

Read more...

"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...

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...

This Week in Spring - November 11th, 2014

Welcome to another installment of This Week in Spring! This week I'm back in Silicon Valley, talking to developers at a handful of large technology-driven companies about taking their first steps with a cloud-native architecture. Interesting feedback, as ever! This week I'll be doing a meetup here in the bay area on building Bootiful microservices with Spring Cloud. Next week, I look forward to seeing people at Java2Days in Sofia, Bulgaria! C'ya there!

  1. Spring Integration lead Gary Russell has just announced Spring Integration 4.1.0 and Spring AMQP 1.4.0 final are now available!
  2. Spring Security OAuth 2.0.4.RELEASE Available Now. The new release contains a few nice additions and a few bug fixes, making it a recommended, easy upgrade.
  3. Spring lead Juergen Hoeller just announced the availability of Spring Framework 4.1.2, accompanied by 4.0.8 and 3.2.12 maintenance releases.
  4. I'll be doing a webinar with ZeroTurnaround's Adam Koblentz introducing how to use Spring (and Spring Boot in particular) and JRebel 6. Spring Boot makes Java as productive as it can get, but sometimes you need a little bit more to get around Java's traditionally awful support for things like live-reloading code during development (to expedite iteration). In this webinar, we'll look at how that's done with JRebel!
  5. Continuing the microservice webinar series on Nov 18, mark your calendars for Matt Stine and Donnie Berkholz from Redmonk - Made for Each Other: Microservices + PaaS
  6. With the exception of panel sessions, and a few sessions that had no slides at all :), the SpringOne2GX conference slides are all posted on www.springone2gx.com, in the session details on the schedule page.
  7. The opening keynotes from SpringOne2GX 2014 - both day 1 and day 2 - are now available online! I'd start with day 2, personally, but that's just me... -whistles-
  8. Speaking of SpringOne2GX 2014, Splunk evangelist Damien Dallimore's talk, Gaining Application Lifecycle Intelligence, is now available online as a replay!
  9. New Relic rockstar Ashley Puls's talk from SpringOne2GX 2014, Living in the Matrix with Bytecode Manipulation, is also now available as a replay! If I may be so bold, Ashley was kind enough to do a webinar with me earlier this year on using New Relic for Spring applications, too. Ashley's on a very short list of people I go to when I have questions about the arcane or complex. She's brilliant. Watch those talks and see what I mean!
  10. Speaking of brilliance on a short list, the good Dr. Dave Syer recently did a webinar introducing Spring Security OAuth for microservices. I can't underscore this enough: Dr. Syer is, or has been, the co-founder or project lead of Spring Batch, Spring Security OAuth, Spring Boot, Spring Cloud, a contributor to the Spring framework, and - of course - a senior engineer working on Cloud Foundry. When he talks, I listen and I hope you will too. Check out this video.
  11. Speaking of Spring Cloud, Dr. Syer also just recently announced the M2 release of Spring Cloud. The Spring Cloud example application and the (hopefully imminently more accessible, but trivial) application that I've been using to showcase Spring Cloud have both been updated to use Spring Cloud M2.
  12. Pivotal's very own Tim Spann pu together a very nice post on using Spring XD to load files into Pivotal HD's HAWK
  13. Sergei Egorov put together a nice post on building microservices using Thrift, the serialization mechanism that's pretty in-vogue in the big-data space
  14. Want to build a REST service and expose documentation about it? Swagger's one way to go. I'm not sure it's the best (it's 30 MB!), but it's ... something. Here's a nice post using Swagger with Spring Boot
  15. Biju Kunjummen has a nice post on using the Spring caching abstraction's support for Google Guava Cache.
  16. The Concretepage introduces a simple Java configuration-centric approach to building a Spring Batch solution
  17. Biju Kunjummen also did a nice writeup of using Spring Session to capture (and work with) an HTTP session from websockets - check this one out!
  18. Trying to access the target object behind an AOP proxy? This post offers one way to do it!
Read more...

This Week in Spring - November 4th, 2014

Welcome to another installment of This Week in Spring! This week I'm on the road talking to enthusiastic Spring developers in Casablanca, Morocco at the JMaghreb conference and then it's off to London (again!) for the amazing Spring eXchange. If you're at either, be sure to say hi!

Read more...

A quality @Qualifier

Sometimes, teh Twitterz is an amazing place. Just last week I spent some time helping clarify the behavior of Spring's @Qualifier annotation, which is both older than JSR 330 and offers a richer superset of JSR 330's @Qualifier annotation. These misguided few seemed to be under the impression that Spring's annotation didn't offer the same degree of type-safety as the JSR 330 annotation. I don't know if it's because they simply hadn't read up on the support (which is fairly new, since it's only been around since 2007), or if it's because they work for companies that make their money if you stop using Spring, but either way it was an excellent opportunity for a refresher!

Read more...

This Week in Spring - October 28, 2014

Hello from New York City! Tonight I'll be addressing the Cloud Foundry User Group on how to build Spring Boot and Spring Cloud-based microservices that run on Cloud Foundry - I hope you'll join us! And if you're in Boston, then come hang out when I give the same talk there on Thursday!

Read more...