
- 264 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
eBook - ePub
Spring Boot in Action
About this book
Summary
A developer-focused guide to writing applications using Spring Boot. You'll learn how to bypass the tedious configuration steps so that you can concentrate on your application's behavior.
Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications.
About the Technology
The Spring Framework simplifies enterprise Java development, but it does require lots of tedious configuration work. Spring Boot radically streamlines spinning up a Spring application. You get automatic configuration and a model with established conventions for build-time and runtime dependencies. You also get a handy command-line interface you can use to write scripts in Groovy. Developers who use Spring Boot often say that they can't imagine going back to hand configuring their applications.
About the Book
Spring Boot in Action is a developer-focused guide to writing applications using Spring Boot. In it, you'll learn how to bypass configuration steps so you can focus on your application's behavior. Spring expert Craig Walls uses interesting and practical examples to teach you both how to use the default settings effectively and how to override and customize Spring Boot for your unique environment. Along the way, you'll pick up insights from Craig's years of Spring development experience.
What's Inside
About the Reader
Written for readers familiar with the Spring Framework.
About the Author
Craig Walls is a software developer, author of the popular book Spring in Action, Fourth Edition, and a frequent speaker at conferences.
Table of Contents
A developer-focused guide to writing applications using Spring Boot. You'll learn how to bypass the tedious configuration steps so that you can concentrate on your application's behavior.
Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications.
About the Technology
The Spring Framework simplifies enterprise Java development, but it does require lots of tedious configuration work. Spring Boot radically streamlines spinning up a Spring application. You get automatic configuration and a model with established conventions for build-time and runtime dependencies. You also get a handy command-line interface you can use to write scripts in Groovy. Developers who use Spring Boot often say that they can't imagine going back to hand configuring their applications.
About the Book
Spring Boot in Action is a developer-focused guide to writing applications using Spring Boot. In it, you'll learn how to bypass configuration steps so you can focus on your application's behavior. Spring expert Craig Walls uses interesting and practical examples to teach you both how to use the default settings effectively and how to override and customize Spring Boot for your unique environment. Along the way, you'll pick up insights from Craig's years of Spring development experience.
What's Inside
- Develop Spring apps more efficiently
- Minimal to no configuration
- Runtime metrics with the Actuator
- Covers Spring Boot 1.3
About the Reader
Written for readers familiar with the Spring Framework.
About the Author
Craig Walls is a software developer, author of the popular book Spring in Action, Fourth Edition, and a frequent speaker at conferences.
Table of Contents
- Bootstarting Spring
- Developing your first Spring Boot application
- Customizing configuration
- Testing with Spring Boot
- Getting Groovy with the Spring Boot CLI
- Applying Grails in Spring Boot
- Taking a peek inside with the Actuator
- Deploying Spring Boot applications
APPENDIXES
- Spring Boot developer tools
- Spring Boot starters
- Configuration properties
- Spring Boot dependencies
Frequently asked questions
Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription.
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn more here.
Perlego offers two plans: Essential and Complete
- Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
- Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, weâve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes! You can use the Perlego app on both iOS or Android devices to read anytime, anywhere â even offline. Perfect for commutes or when youâre on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Yes, you can access Spring Boot in Action by Craig Walls in PDF and/or ePUB format, as well as other popular books in Computer Science & Computer Science General. We have over one million books available in our catalogue for you to explore.
Information
Chapter 1. Bootstarting Spring
This chapter covers
- How Spring Boot simplifies Spring application development
- The essential features of Spring Boot
- Setting up a Spring Boot workspace
The Spring Framework has been around for over a decade and has found a place as the de facto standard framework for developing Java applications. With such a long and storied history, some might think that Spring has settled, resting on its laurels, and is not doing anything new or exciting. Some might even say that Spring is legacy and that itâs time to look elsewhere for innovation.
Some would be wrong.
There are many exciting new things taking place in the Spring ecosystem, including work in the areas of cloud computing, big data, schema-less data persistence, reactive programming, and client-side application development.
Perhaps the most exciting, most head-turning, most game-changing new thing to come to Spring in the past year or so is Spring Boot. Spring Boot offers a new paradigm for developing Spring applications with minimal friction. With Spring Boot, youâll be able to develop Spring applications with more agility and be able to focus on addressing your applicationâs functionality needs with minimal (or possibly no) thought of configuring Spring itself. In fact, one of the main things that Spring Boot does is to get Spring out of your way so you can get stuff done.
Throughout the chapters in this book, weâll explore various facets of Spring Boot development. But first, letâs take a high-level look at what Spring Boot has to offer.
1.1. Spring rebooted
Spring started as a lightweight alternative to Java Enterprise Edition (JEE, or J2EE as it was known at the time). Rather than develop components as heavyweight Enterprise JavaBeans (EJBs), Spring offered a simpler approach to enterprise Java development, utilizing dependency injection and aspect-oriented programming to achieve the capabilities of EJB with plain old Java objects (POJOs).
But while Spring was lightweight in terms of component code, it was heavyweight in terms of configuration. Initially, Spring was configured with XML (and lots of it). Spring 2.5 introduced annotation-based component-scanning, which eliminated a great deal of explicit XML configuration for an applicationâs own components. And Spring 3.0 introduced a Java-based configuration as a type-safe and refactorable option to XML.
Even so, there was no escape from configuration. Enabling certain Spring features such as transaction management and Spring MVC required explicit configuration, either in XML or Java. Enabling third-party library features such as Thymeleaf-based web views required explicit configuration. Configuring servlets and filters (such as Springâs DispatcherServlet) required explicit configuration in web.xml or in a servlet initializer. Component-scanning reduced configuration and Java configuration made it less awkward, but Spring still required a lot of configuration.
All of that configuration represents development friction. Any time spent writing configuration is time spent not writing application logic. The mental shift required to think about configuring a Spring feature distracts from solving the business problem. Like any framework, Spring does a lot for you, but it demands that you do a lot for it in return.
Moreover, project dependency management is a thankless task. Deciding what libraries need to be part of the project build is tricky enough. But itâs even more challenging to know which versions of those libraries will play well with others.
As important as it is, dependency management is another form of friction. When youâre adding dependencies to your build, youâre not writing application code. Any incompatibilities that come from selecting the wrong versions of those dependencies can be a real productivity killer.
Spring Boot has changed all of that.
1.1.1. Taking a fresh look at Spring
Suppose youâre given the task of developing a very simple Hello World web application with Spring. What would you need to do? I can think of a handful of things youâd need at a bare minimum:
- A project structure, complete with a Maven or Gradle build file including required dependencies. At the very least, youâll need Spring MVC and the Servlet API expressed as dependencies.
- A web.xml file (or a WebApplicationInitializer implementation) that declares Springâs DispatcherServlet.
- A Spring configuration that enables Spring MVC.
- A controller class that will respond to HTTP requests with âHello Worldâ.
- A web application server, such as Tomcat, to deploy the application to.
Whatâs most striking about this list is that only one item is specific to developing the Hello World functionality: the controller. The rest of it is generic boilerplate that youâd need for any web application developed with Spring. But if all Spring web applications need it, why should you have to provide it?
Suppose for a moment that the controller is all you need. As it turns out, the Groovy-based controller class shown in listing 1.1 is a complete (even if simple) Spring application.
Listing 1.1. A complete Groovy-based Spring application
@RestController class HelloController { @RequestMapping("/") def hello() { return "Hello World" } } Thereâs no configuration. No web.xml. No build specification. Not even an application server. This is the entire application. Spring Boot will handle the logistics of executing the application. You only need to bring the application code.
Assuming that you have Spring Bootâs command-line interface (CLI) installed, you can run HelloController at the command line like this:
$ spring run HelloController.groovy
You may have also noticed that it wasnât even necessary to compile the code. The Spring Boot CLI was able to run it from its uncompiled form.
I chose to write this example controller in Groovy because the simplicity of the Groovy language presents well alongside the simplicity of Spring Boot. But Spring Boot doesnât require that you use Groovy. In fact, much of the code weâll write in this book will be in Java. But thereâll be some Groovy here and there, where appropriate.
Feel free to look ahead to section 1.21 to see how to install the Spring Boot CLI, so that you can try out this little web application. But for now, weâll look at the key pieces of Spring Boot to see how it changes Spring application development.
1.1.2. Examining Spring Boot essentials
Spring Boot brings a great deal of magic to Spring application development. But there are four core tricks that it performs:
- Automatic configurationâ Spring Boot can automatically provide configuration for application functionality common to many Spring applications.
- Starter dependenciesâ You tell Spring Boot what kind of functionality you need, and it will ensure that the libraries needed are added to the build.
- The command-line interfaceâ This optional feature of Spring Boot lets you write complete applications with just application code, but no need for a traditional project build.
- The Actuatorâ Gives you insight into whatâs going on inside of a running Spring Boot application.
Each of these features serves to simplify Spring application development in its own way. Weâll look at how to employ them to their fullest throughout this book. But for now, letâs take a quick look at what each offers.
Auto-configuration
In any given Spring applicationâs source code, youâll find either Java configuration or XML configuration (or both) that enables certain supporting features and functionality for the application. For example, if youâve ever written an application that accesses a relational database with JDBC, youâve probably configured Springâs JdbcTemplate as a bean in the Spring application context. Iâll bet the configuration looked a lot like this:
@Bean public JdbcTemplate jdbcTemplate(DataSource dataSource) { return new JdbcTemplate(dataSource); } This very simple bean declaration creates an instance of JdbcTemplate, injecting it with its one dependency, a DataSource. Of course, that means that youâll also need to configure a DataSource bean so that the dependency will be met. To complete this configuration scenario, suppose that you were to configure an embedded H2 database as the DataSource bea...
Table of contents
- Copyright
- Brief Table of Contents
- Table of Contents
- Foreword
- Preface
- About this Book
- Acknowledgments
- Chapter 1. Bootstarting Spring
- Chapter 2. Developing your first Spring Boot application
- Chapter 3. Customizing configuration
- Chapter 4. Testing with Spring Boot
- Chapter 5. Getting Groovy with the Spring Boot CLI
- Chapter 6. Applying Grails in Spring Boot
- Chapter 7. Taking a peek inside with the Actuator
- Chapter 8. Deploying Spring Boot applications
- Appendix A. Spring Boot Developer Tools
- Appendix B. Spring Boot starters
- Appendix C. Configuration properties
- Appendix D. Spring Boot dependencies
- Index
- List of Figures
- List of Tables
- List of Listings