Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Spring Boot Cookbook
  • Table Of Contents Toc
Spring Boot Cookbook

Spring Boot Cookbook

By : Alex Antonov
4.6 (5)
close
close
Spring Boot Cookbook

Spring Boot Cookbook

4.6 (5)
By: Alex Antonov

Overview of this book

Spring Boot is Spring's convention-over-configuration solution. This feature makes it easy to create Spring applications and services with absolute minimum fuss. Spring Boot has the great ability to be customized and enhanced, and is specifically designed to simplify development of a new Spring application. This book will provide many detailed insights about the inner workings of Spring Boot, as well as tips and recipes to integrate the third-party frameworks and components needed to build complex enterprise-scale applications. The book starts with an overview of the important and useful Spring Boot starters that are included in the framework, and teaches you to create and add custom Servlet Filters, Interceptors, Converters, Formatters, and PropertyEditors to a Spring Boot web application. Next it will cover configuring custom routing rules and patterns, adding additional static asset paths, and adding and modifying servlet container connectors and other properties such as enabling SSL. Moving on, the book will teach you how to create custom Spring Boot Starters, and explore different techniques to test Spring Boot applications. Next, the book will show you examples of configuring your build to produce Docker images and self-executing binary files for Linux/OSX environments. Finally, the book will teach you how to create custom health indicators, and access monitoring data via HTTP and JMX.
Table of Contents (9 chapters)
close
close
8
Index

Launching an application using Gradle

Typically, the very first step of creating any application is to have a basic skeleton, which can be immediately launched as is. As the Spring Boot starter has created the application template for us already, all we have to do is extract the code, build, and execute it. Now let's go to the console and launch the app with Gradle.

How to do it…

  1. Change in the directory where the bookpub.zip archive was extracted from and execute the following command from the command line:
    $ ./gradlew clean bootRun
    

Tip

If you don't have gradlew in the directory, then download a version of Gradle from https://gradle.org/downloads or install it via homebrew by executing brew install gradle. After Gradle is installed, run gradle wrapper to get the Gradle wrapper files generated. Another way is to invoke gradle clean bootRun in order to achieve the same results.

The output of the preceding command will be as follows:


  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::  (v1.2.3.BUILD-SNAPSHOT)

2015-03-09 23:18:53.721 : Starting BookPubApplication on mbp with PID 43850 
2015-03-09 23:18:53.781 : Refreshing org.springframework.context.annotation.Annotatio
2015-03-09 23:18:55.544 : Building JPA container EntityManagerFactory for persistence 
2015-03-09 23:18:55.565 : HHH000204: Processing PersistenceUnitInfo [name: default	
2015-03-09 23:18:55.624 : Hibernate Core {4.3.8.Final}
2015-03-09 23:18:55.625 : HHH000206: hibernate.properties not found
2015-03-09 23:18:55.627 : HHH000021: Bytecode provider name : javassist
2015-03-09 23:18:55.774 : HCANN000001: Hibernate Commons Annotations {4.0.5.Final
2015-03-09 23:18:55.850 : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2015-03-09 23:18:55.902 : HHH000397: Using ASTQueryTranslatorFactory
2015-03-09 23:18:56.094 : HHH000227: Running hbm2ddl schema export
2015-03-09 23:18:56.096 : HHH000230: Schema export complete
2015-03-09 23:18:56.337 : Registering beans for JMX exposure on startup
2015-03-09 23:18:56.345 : Started BookPubApplication in 3.024 seconds (JVM running...
2015-03-09 23:18:56.346 : Closing org.springframework.context.annotation.AnnotationC..
2015-03-09 23:18:56.347 : Unregistering JMX-exposed beans on shutdown
2015-03-09 23:18:56.349 : Closing JPA EntityManagerFactory for persistence unit 'def…
2015-03-09 23:18:56.349 : HHH000227: Running hbm2ddl schema export
2015-03-09 23:18:56.350 : HHH000230: Schema export complete
BUILD SUCCESSFUL
Total time: 52.323 secs

How it works…

As we can see, the application started just fine, but as we didn't add any functionality or configure any services, it terminated right away. From the startup log, however, we do see that the autoconfiguration did take place. Let's take a look at the following lines:

Building JPA container EntityManagerFactory for persistence unit 'default'
HHH000412: Hibernate Core {4.3.8.Final}
HHH000400: Using dialect: org.hibernate.dialect.H2Dialect

This information tells us that because we added the jdbc and data-jpa starters, the JPA container was created and will use Hibernate 4.3.8.Final to manage the persistence using H2Dialect. This was possible because we had the right classes in the classpath.

Tip

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Spring Boot Cookbook
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon