 Is it running? All right. So welcome to everyone, and thanks for showing up. My name is Sergio Amar. I was here last year actually. I'm not sure how many of you were in my last talk. Some of you. All right. Great. So today we're going to talk about the Spring Boot. We're going to see a little bit about the new features in Spring Boot 1.3. How many of you use the Spring Boot right now? Half of the room? How many of you use the Spring? So how many of you came for the beers? Great. Awesome. All right. So before getting started, I also want to make an announcement. So I'm the organizer of the Spring IO conference. It's basically the biggest European conference in Spring, so entirely for the Spring ecosystem. It's going to happen in Barcelona. That's my hometown. That's where I'm based. And that's going to be the 19th and 20th of May. We just opened the call for papers. So if you have something interesting to say, share. Just feel free to go to springio.net and just send your proposal. So I'm just going to pass a quick video on last year edition. So it's like a two-minute video. But at least you'll be able to see how it was. It's a great pleasure for me to see Spring IO reappearing as a European conference. And the choice of Barcelona is just the perfect fit. Very nice atmosphere here, international mix of attendees. The potential for a Spring conference in Europe is just enormous. And there really should be a yearly Spring event in Europe again. And this is a perfect choice. Here at Spring IO, 2015 in beautiful Barcelona, Spain, having a great time. Some of the best developers in the world, leading experts on Spring, Groovy, Cloudy products and stuff like that, really getting a chance to talk some of the best developers around, great talks, enjoying the conference. It's really the biggest conference in Europe where you can meet Spring people. And in particular, the Spring, the engineering team, the people who actually write the software. G is amazing. He knows everybody. There's constant feedback. There's constant, everyone's asking questions. Obviously, there's most of the Spring crew here, so it's great to catch up with the guys. I've learned a lot, actually. I've learned a lot just talking to users of the technology, people out there in the community. It's been a very, very good conference. I'm really quite pleased. I hope this becomes sort of the effective Spring experience in Europe. It's amazing. This event has proven to be an incredible success because it has drawn people from all over continental Europe, and I mean all over, from the northernmost and the easternmost borders. It's a really great place and a really great conference to see everybody. Spring IO in one or two words, it's a superb conference. I mean, it's the Spring event of Europe. Right. So that was it. So basically, this year again, if you are into the Spring community, you should attend either Spring IO or Spring One in the US, which is basically the two main conferences to meet the Spring ecosystem, the Spring people. All right, so having said that, let's get started. So we come from a long time ago, right? So actually, the Spring, the first version, the first milestone came out back in 2004. In 2006, we had a really nice improvement on the XML configuration because we had the namespaces added to the XML configuration, which simplified quite a lot the configuration. But still, the XML is quite verbose and ever-prone. It's not type safe. So back in 2007, when Spring 2.5 was introduced, the MVC layer was completely renewed and refactored to use annotations. So we see something like request mapping, request pattern. And those annotations, this kind of programming model is the programming model that we still use today, right? In 2009, when Spring 3.0 was released, we introduced a new configuration style, which is called the Java config, right? And that's basically what Spring Boo is using mainly, right? So it's the Java configuration style instead of the XML's annotations. So we have three ways of configuring Spring, basically, Java, XML annotations. We're going to see that Spring Boo goes more into the Java site. In Spring 3.1, the profiles were introduced as well. And this was a really nice addition to the framework because profiles allow us to basically have a configuration for different environments. So you could have, for instance, a data source for testing, for production, for QA, right? So you could configure a bin differently, depending on the environment where you were. And finally, version one of Spring Boot came out in 2014. It just happened that Spring Boot had a really good traction, right? So a really good adoption as well. And we're going to see that in the next slide because Spring Boot happens to be one of the most downloaded frameworks. I would say this is the most downloaded framework for microservices as well. So what does Spring Boot? Spring Boot is basically an opinionated runtime for Spring projects. That means that we're going to rely on conventions over configuration, right? So it's basically, Spring Boot will basically configure several parts of your application based on some defaults or some things that you have in the class path, some properties, right? So no XML anymore. So everything will be in Java. No code generation. So how many of you use Spring Roo here in the room? Some of you, right? So Spring Roo was all about code generation. Spring Boot is something completely different. It's basically what brings the fun back again to the Spring framework, right? So it's the fun way to develop the Spring. So if you have a greenfield development, if you start a project from scratch, you should definitely check out Spring Boot. You should start with Spring Boot. So it supports many types of applications like web applications, integration applications, cloud applications, batch applications. And it basically removes all the boilerplate configurations. So actually the framework can predict more or less what you're going to be using. So if you have a web application, for sure, you need a servlet container or you need Jackson because you'll be dealing with JSONs. So all these can be predicted. So Spring Boot will try to predict all this stuff and auto-configure the different parts of your application. So who's using Spring Boot? So if we see this graph here, we see that last month in December, Spring Boot broke the barrier of 2 million downloads. So that's quite a lot. And this is the most downloaded framework for microservices as well. So Spring Boot is basically the way to go. And if you take a look at this picture here, we see that at the top level in the application framework level, we find a Spring Cloud and Spring Boot. So if you are into a microservice architecture, Spring Cloud, Spring Boot, and Cloud Foundry is the perfect combination. So how many of you heard about Spring Cloud here? Some of you. We're not going to talk about Spring Cloud today, maybe some other day. But Spring Boot or actually Spring Cloud is based on a Spring Boot. And it's actually the perfect fit for a microservice architecture. So we're going to focus on this layer here, basically on the application framework, where we see that Spring Boot will give us basically the rapid development. So how to get from zero to a complete app in five minutes. And Spring Cloud will give us all the tools for whenever you want to build a distributed system. So it's going to give you all the patterns implemented for distributed systems, which are quite complex. And you're going to see that Spring Boot plus Spring Cloud will give you a microservice architecture just in a simple minute. So just to be on the same page, we're going to do a quick demo on Spring Boot. We're going to just start a Spring Boot project. We're going to use this Spring Boot project for the new features in Spring Boot 1.3. So basically I'm using the STS. I'm going to start a new project. Hopefully the Wi-Fi will behave properly. So SG Boot Demo, and I'm going to choose that I want a Gradle project. How many of you use Gradle here? Not much, huh? Most of you, Maven? Almost all the room. Time to check out Gradle as well. So SG Boot Demo on SG does this again. All right, so notice the packaging here. We're going to build a web application, but we're going to package it as a jar file, right? So in a traditional approach, you would choose a war file. Well, let's call it traditional or old-fashioned as you want. But we're going to make the jar another war, like just long says, right? So we're going to package a jar file, and this jar file will have an embedded container. So it will expose itself to HTTP. So we're going to choose the wood version. So I'm going to take some risks. I'm going to take the snapshot, current snapshot, and notice how we can choose from a lot of flavors. We're going to choose the web flavor plus the activator flavor plus time leaf. But we see that we have a lot to choose from. We have from core components to data access components from the cloud components. So we're going to keep it simple, right? A real simple application. We're going to start with a simple web application. So notice how we are connecting with the start.spring.io, that was fast, right? So start.spring.io is basically a website that you should know about. So it's basically another way to start the spring boot project. So it basically has the same features that I just shown you. And this will create a zip file. So you're going to have a Maven or Gradle project with the dependencies that you chose. So we have already the project here. So we're going to start the project. And we see that we have a main class. So it's nothing fancy. Annotated with spring boot application. And we're going to create a web application. So I'm going to create a controller. And I'm going to define an endpoint, quest mapping, create, for instance, a string, say hi. And I'm going to pass a request parameter, sorry, called name. How many of you use Java 8? Happy days. All right. Great. So I have my endpoint. I have a really non-emotional, if I know how to spell it. Great. So I have an endpoint called create. It expects optional. I didn't choose Java 8, maybe. Java 8, yes. So you're going to use a REST controller? I wanted to create an endpoint with Timelift. So that's why I choose a controller. But yeah, as Michael said, you could use a REST controller. Here, that's another option that was introduced in spring 4. But for now, I'm going to use the REST controller. And I'm going to define here a respawns body. All right. Great. And this guy here is complaining because of, I don't know why it's complaining here. Why did you came here? OK. Great. Happy days. So this is the only thing that I need to get an application up and running. So notice that I haven't configured any topic. I haven't configured anything in spring. I just have a started class. And I can just start it as a normal application. So I can just go run it as a Spring Boot application. This will start in some seconds. To start it, I can go to localhost 8080 slash greet. Greet. And, well, it's telling me hi anonymous. If I pass a name, like Sergey, which is my name, it's telling me hi Sergey. So quite straightforward. No configuration. And that's what Spring Boot is all about. Great. So if we take a look at the new features of Spring Boot 3.1.3, which is the current release, Spring Boot 1.3 is based on Spring Framework 4.2. So that means that this is the requirement. If you're using Spring 3, then you won't be able to use Spring Boot 1.3. It's also using Spring Security 4. So if you choose to use Spring Security 4, Spring Security, it will take the version 4. And imagine or not, the most successful feature in Spring Boot 1.3 have been the colorful art banners. So that's why I just put it here in the first thing. So if you're not aware of that, when I start the application, I have this really nice banner here that you can overwrite. So you can overwrite by creating a file. No, not this one here. I'm going to create a file called banner.txt. And you can go to online ACRs. Check. I use that quite a lot. I'm just going to grab it from here. I have it. So this is the ACR that I just created. So now when I start the application, I should see this ACR on my console. It just happens that my console is not configured to show colors. But in Spring Boot 1.3, you can have colorful banners. So I can just go to the console just to show you just real quick. And that's going to be SG Boot demo. I'm just going to create a build in just a second. And we're going to see it on the console in just a second. So that's just a joke. But it's true that a lot of people were interested in this feature, right? Java minus jar. And I'm going to choose this here. So notice how I start the application. I start the application using Java minus jar. So there's no Tomcat here. So Spring Boot will pull in an embedded Tomcat. And it will start the application with the embedded Tomcat. So I can have an executable jar with Java minus jar. And we see here that now we have colors in the ACR banner. OK, great. So let's go for the interesting stuff or the serious stuff. Because I would say that the most interesting feature in 1.3 is the developer tools. So developer tools will give you a lot of productivity on the development of your Spring Boot applications. So it will provide some sensible, proper defaults. I'm going to talk about that in a second. It will provide automatic application restart, remote development support, live reload support, and persistent HTTP sessions. So let's do a demo on that on every single topic. And let's see what that means. So I'm going to take the same application in here. And if I go to the browser on localhost 8080, yeah, great. Here you go. And if I just want to change something in here, hi there. What happens is that I have to restart the application to see the changes, right? So I have to go here. And I have to restart the application, wait some time, until the application is deployed again. Well, I have to close this one here. So let's do it again. So I have to wait some time until I see the changes. Let's put that in here. So now I kind of refresh. And I'm going to see the changes. So I'm going to introduce a new dependency, which is the DevTools. So dependency in a Spring Boot is usually a starter project. Notice that the main dependencies are just these four here. And these four here will pull in all the dependencies required for my application to run. So I'm going to add a new dependency, which is the DevTools. I'm going to add it here. And I'm going to refresh the project. Gradle, refresh all. And these will pull in the DevTools. So now we're going to get some nice features. I'm going to stop the current application here. And I'm going to start it again. So hopefully, this will run with DevTools now. All right, it's running here. But notice how if I change something, there's an automatic restart. Have you seen that in here? Let me do it again. So it has a start now. So hey, back. I'm going to save and see the restart happening here. So I can come here and just see the updated values. And you say, OK, so it's just a restart. But it's not a restart. So let's see what a restart is and what Spring DevTools is doing. So I'm going to restart using the IDE. OK, so if I click that button here, it's going to restart the application. So I'm going to click that. I'm going to check the console. And I'm going to check the time that it took to start the application. It took five seconds. All right, can you see that? So let's do a change here. And let's see how long it takes to start. Bank, one second. How is that possible? Because Spring DevTools is creating two class loaders. There's a root class loader with all your dependencies. So whenever you start the application, the class loader needs to load all the classes into it. So Spring Boot has a root class loader with all your dependencies or your jar files, the classes in your jar files that won't change. And it has a kind of child class loader. And in this child class loader, you will find your classes, your application classes. So whenever there's a restart, only the child class loader gets refreshed, and not the root class loader. So that's why we get a significant improvement in the reload of the application. So that's not a restart. It's actually a reloading. That's it. Actually, it's a really nice feature. But as we are changing the application, we're going to see the changes reflected into my browser. But there's even more. If I can get that into here, why I don't see it. Let me see if I can see that. Where have you gone? Oh, here you go. It's in here. Here you go. So what I'm going to do is to enable something called the live reload. So that's basically creating a live reload server. So apart from reloading the application, what I will see now is that these changes are going to be reflected to my browser automatically without having to refresh my browser. So I'm going to just type hi there here. And I'm going to see that this has refreshed. And I see the changes automatically in here. I haven't refreshed the page at all. So that happened automatically for me. So this is just a rest call. But imagine that I have a normal request. Let's call it grid 2. A normal request using a timely, for instance, public, string, say, hi. 2, I'm going to pass the same parameters here. Let's see here. And a model. So in a traditional application, we have a model, which is the contract between the controller and the view. And I'm going to add to the model the attribute name. Sorry. Name or else, anonymous, all right. I'm going to return a view, which is going to be grid, for instance. So Spring Boot, if you use any of the templating frameworks, we'll expect the templates to be under the template directory. So I'm going to create a new file into the template directory called grid.html. I'm going to cheat a little bit and get my template, my Timelift template that I had. So I have the name here. And I'm going to start the application again and see that I get access to this page. So grid 2. So grid 2 actually renders this application here. So if I change the HTML here, I'm going to see that this has changed as well. So the reloading not only happens to the Java classes, but it also happens to the static resources. So I see that this is a Timelift file. And this gets also refreshed when I change something in here to the browser automatically. So the Spring Dev Tools for Timelift basically gets rid of the cache. Timelift provides a cache. So whenever you render a template, this template is cached. So if you make any change to the template, you won't see anything on the browser because it has been cached. Even if you refresh it, there are no changes applied on the browser side. So DevTools will basically get rid of these caches if you are in development mode. So that's one of the features that the DevTools will give you. Apart from that, you can do the same thing with remote applications. So imagine that you take this application and you push it into Cloud Foundry. How many of you know about Cloud Foundry? Some of you. So Cloud Foundry is basically a pass where you can deploy your applications. So if you take this application and deploy it into Cloud Foundry, you can even get the same feature. So you can have the automatic changes and the automatic reload in a remote location. So that also happens remotely, not only locally here. If we have time, we're going to cover it. But I think that we have more 15 minutes or? Yeah, if you see. OK, let's continue. And let's see if we have more time later on. So next thing that Spring Boot 1.3 is providing is auto-configuration for the caching layer. So Spring Boot has a caching abstraction layer. So you can use some abstraction for caching and use any caching implementation underneath, which can be EH cache, could be Heizel cache, could be RedEase, could be any of the implementations of the GSR 107, could be anything. So you basically use some annotations in your application and Spring will basically define something called the cache manager, which will be packed by one of these cache technologies. So in Spring Boot 1.4, you can have caching with a simple annotation. Just by providing some of the dependencies into the class path, Spring Boot will auto-configure a cache for you. So let's see how this works. So we're going to create a class here, which will be the greeter. And we're going to create a simple, let's stop that, a simple method, public, string, greet message, a really simple class. I'm going to annotate it with component. I'm gonna use it in here, so never do that. All right, I'm going to use this guy here and I'm going to apply a cache on this guy. So now instead of this, I'm going to call the greeter.greetMessage, okay, correct. So this greeter will be a really, really slow guy or maybe you can do a sysout, so it's gonna be easier. I mean, so I'm going to use caching in here. So we don't have to go into the method over and over again. So I imagine that this method takes a lot of time to execute, so I can use some annotations like cacheable to say that this method can be cacheable. And the way that this will be cached depends on how you can figure your application context. It could be cached by Redis, it could be cached by HazelCache, it could be cached by anything, right? So I'm going to add a cache like message. That's the name of the cache. A cache could be a simple concurrent hash map as well, so it could be anything, right? So I'm going to add a cache and I'm going to set Redis as the cache implementation. So how can we make the cache work without almost zero configuration? So the first thing that we'll do is to add some dependencies into my project. Actually, I'm going to add a dependency called cache, a starter cache and a dependency called starter Redis. So this will pull in all the required dependencies for caching and for Redis. So only two dependencies, they're going to be my class path and a Spring Boot will auto-detect them and we'll just know that Spring Boot can use Redis as a cache implementation. So I'm going to update my project, grade on, refresh all, and I'm going to add a simple annotation called at enable caching. Has been a long day. All right, so this annotation at enable caching, it will enable the cache layer based on the dependencies that I have in my class path. So I'm going to start now my application and I'm going to call the grade method, right? So we see here that we got this system out called I'm in, right, so that was the first time we called it. Second time, third time, fourth time. So we see that only one time I'm in was called. And so that means that the cache applied. We haven't called that method multiple times. And we can actually check whether that's true or not. All right, so I can go to Redis and I can check the keys of Redis and I see that the second key is actually the anonymous. So this part here is actually done by a spring data. It's because of the Java serialization, right? But you can change that, but at least we see that this is the key that we just cached. So if I can come to, if I go to the endpoint again and I change the parameter, grade, name, equal surgery. So that's another value, right? So we see that we got into the method from the grader. But if I just hit the endpoint multiple times now, we see that only one time I'm in was shown in the console. We can go to Redis again and we see that there's another entry called surgery, right? In here. So that means that this value was cached into Redis. So one annotation, two extra dependencies and we got caching working in our application. And that works for Hazelcast and a bunch of cache implementations that we have seen on the slides, right? It just happens that we use Redis, but this works for many implementations. More stuff, more auto-configuration for Cassandra, for a spring session for OAuth, for Jock, for Sangrid, for Termis. We're not gonna show all of them, right? All the auto-configuration, but well, the same that we have seen for caching works for all these different technologies. How many of you heard about the spring session? Mm-hmm, mm-hmm, mm-hmm. Wow, so there's a lot to do, huh? When you go at home. Ha, ha, ha. So spring session, five minutes only, wow. Spring session, basically, lets you externalize the HTTP session into Redis, Hazelcast, right? So currently we have these two implementations, but at least you will have portable HTTP sessions. So if you have your application and it dies, your session repository won't die along, right? So that's especially important in the cloud environment where you have different containers, and those containers can be disposed, can be recreated, right? So you cannot rely on the default strategy for session persistence, right? So you need to externalize the state into an external repository. So let's take a look at how this works. We're going to do it real quick, right? We have a second project here configured, and this second project has a really simple endpoint with a counter, right? So it basically gets a counter from the session, session updates it and shows the counter. So let's start this project here. Localhost 8080. It has some security in it. No, that's not the credential, sir, J123, right? So we have here the counter, one, two, three, four, five, six, seven, eight, nine, 10, right? So it just happens that if you have like a load balancer and multiple instances of this application deployed, if you have sticky sessions, well, you're going to go to the same instance of the application, but in the cloud for instance, if these instance dies for some reason, because maybe you scale down or scale up, your session is gone as well. So the only way to maintain the state is by externalizing this state into a external repository. So Spring Session allows you to do that by simply, where am I? Here you go. Well, Spring Boot and Spring Session allows you to do that by simply adding one dependency, which is this one here, a Spring Session, right? So Spring Boot 1.3 will detect that you have a Spring Session in the class path, and it will also detect that you have Redis in the class path. So if you have these two dependencies in the class path, we'll automatically configure your application to store all the HTTP state directly into Redis. Notice that you don't have to change anything on your application side. On your application side, you still use the servlet API components. I'm using the HTTP Session, but it just happens that Spring Boot, Spring Session, will wrap the HTTP request, and whenever you get a session and store something into the session, we'll store it into a Spring Session repository, which could be Redis, could be Hazelcast. So if I go to the CLI here, and I do keys star, I see that I got some keys from my sessions. So these sessions basically belong to the session I just started. So if I go back to this URL, I can keep on refreshing nine, 10, 11. This endpoint is protected. It has a session, right? So notice how if I flushed everything from Redis, so now Redis is empty, and I refresh this endpoint, I'm brought back to the login page because there's no session. I just killed my session because all my session state was on Redis. It was externalized. All right, so this is a quite nice feature. Another feature is fully executable JAR files. So as you have seen before, I started the application using Java Miner JAR, right? So this JAR file is a Uber JAR, which contains not only your application code, but also all the dependencies. So notice that the JAR file is quite big, right? Compared to the original JAR file. The original JAR file has only your application code, but the Uber JAR file contains everything. So we just started the JAR file using Java Miner JAR. But in Spring Boot, what you can do is to execute the JAR file like a normal script. So to do that, you'll have to change slightly your build. I'm going to add this line here. Spring Boot executable equals stroom. And now I'm going to rebuild the application again. Gradle build, this will generate another JAR file. Let me stop this guy. And now, if I check these JAR files, I will start the JAR file. Why not? Shit, what? Let's see if that works. Mm-mm-mm. We will text this JAR file. Oh, I added that into the Spring Boot session. That was not the project. So let me just add it again here. Rebuild it. Sorry. Rebuild it. And this is a really good feature because you can just add your application into the init scripts, for instance. You can create a symbolic link to the init script and just make your application start when your server starts as well. So let's see if that works now. It doesn't work. It doesn't like it to work. So, mm-mm-mm-mm. We are in the right project. How don't we? Mm-hmm, mm-hmm, mm-hmm. Well, I have to trust me on that right now. Oh, I have two of them. So I'll have to trust me on that by now. But yeah, what it generates is that if you take a look at the JAR file, the first part of the JAR file is by just script that will make the JAR automatically start with dot slash and the name of the JAR file. Let's keep it in the background. There are actually more features on a Spring Boot 1.3. So I guess that these were the most important ones, the developer tools, the caching, auto-configuration, all the other configuration, the Spring Session configuration, the full executable JARs. Actually, we have also support for auto-configuration of web serverlets, web filters and web listeners. If you have a class with these annotations and we use the serverlet components scan annotation, these will be automatically picked up. There are actually a lot more features in Spring Boot 1.3, minor features, which we're not gonna cover. So if you're currently using Spring Boot 1.3, two for instance, and you want to migrate to 1.3, there are some properties that have been renamed. So make sure that you're not using one of them, otherwise they won't work. Also, Spring Boot chooses the versions of the dependencies for you. That means that if you're using the core in Spring Boot 1.3, you will upgrade to a Spring Framework 4.3. So this happens for all your dependencies or for most of the dependencies. So make sure that your application is happy with the upgrading of these dependencies as well. So you can check these release notes where you're gonna find the migration path and all the features that came out in the Spring Boot 1.3. If you look into the future, Spring Boot 1.4 is planned, is scheduled strategically to feed the Spring IO conference, right? So Spring Boot 1.4 will be released by those days, just before the Spring IO conference. Spring IO conference is May 19th. So if you want to get the state of the art of the Spring ecosystem, make sure to make it to Barcelona. It's a nice place, it's not as hot as here, but you agree that it will be a better weather than here in terms of being less hot, right? And yeah, the next release of Spring 5 or actually the major release is scheduled for 2016, right? Actually this year at the end of the year. So it has comprehensive support for Java 9. The baseline will be Java 8. So if you're not using Java 8 yet, you should start using Java 8, right? Because all the baseline in Spring 5 will be based on Java 8. So we can use all the Java 8 features, right? So more sort of three stuff, HTTP2 and reactive support. That will be one of the most important features in Spring 5, right? The reactive support. If you can, check a project called Spring Reactive, which is basically the initial effort on the reactive support for Spring 5, right? So it's on GitHub already. So make sure to check the Spring Reactive project. All right, so I think that I made it in 45 minutes. All right? Thank you. Thank you, so we have a break up for 10 minutes and then we can have that one about JPM optimizations. Thank you so much. Thank you so much. Thank you so much. Thank you very much.