Spring Boot
{{Short description|Application framework for Java platform}}
{{Infobox software
| name = Spring Boot
| logo = Spring_Boot.svg
| logo_size = 150px
| caption = Spring Boot
| author = Rod Johnson
| developer = VMware
| released = {{Start date and age|2014|04|df=yes}}{{cite web|url=https://github.com/spring-projects/spring-boot/releases/tag/v1.0.0.RELEASE|title=Spring Boot v1.0.0.RELEASE|publisher=github.com}}
| discontinued =
| latest release version = {{wikidata|property|reference|edit|P348}}
| latest release date = {{start date and age|{{wikidata|qualifier|P348|P577}}}}
| latest preview version =
| latest preview date =
| operating system =
| platform = Java EE
| programming language = Java
| genre = Application framework
| license = Apache License 2.0
}}
{{Portal|Free and open-source software}}
Spring Boot is an open-source Java framework used for programming standalone, production-grade Spring-based applications with a bundle of libraries that make project startup and management easier.{{Cite web |date=2023-05-08 |title=Spring Boot Tutorial - Learn Spring Boot |url=https://www.geeksforgeeks.org/spring-boot/ |access-date=2024-04-05 |website=GeeksforGeeks |language=en-US}} Spring Boot is a convention-over-configuration extension for the Spring Java platform intended to help minimize configuration concerns while creating Spring-based applications.{{sfn|Walls|2016|loc=§foreword|p=vii}}{{sfn|Walls|2016|loc=§2.3|pp=37-48}} The application can still be adjusted for specific needs, but the initial Spring Boot project provides a preconfigured "opinionated view" of the best configuration to use with the Spring platform and selected third-party libraries.{{sfn|Walls|2016|loc=§2.4|p=48}}{{sfn|Deinum|Cosmina|2021|loc=§2 Spring Framework Fundamentals|pp=21-22}}
Spring Boot can be used to build microservices, web applications, and console applications.{{Cite web |date=2024-01-08 |title=Spring Boot Console Application |url=https://www.baeldung.com/spring-boot-console-app |access-date=2024-09-20 |website=Baeldung}}
Features
- Embedded Tomcat, Jetty or Undertow web application server.{{sfn|Walls|2016|loc=§1.1.3|p=7}}
- Provides opinionated 'starter' Project Object Models (POMs) for the build tool. The only build tools supported are Maven and Gradle.{{sfn|Walls|2016|loc=§Preface|p=x}}{{sfn|Musib|2022|loc=§1.2.1 Maven vs Gradle| p=9}}
- Automatic configuration of the Spring Application.{{sfn|Walls|2016|loc=§1.1.2|pp=4-5}}
- Provides production-ready{{sfn|Walls|2016|loc=§foreword|p=vii}} functionality such as metrics,{{sfn|Walls|2016|loc=§7|pp=124-139}} health checks,{{sfn|Walls|2016|loc=§7|pp=124-139}} and externalized configuration.{{sfn|Walls|2016|loc=§3.1-§3.2.3|pp=49-69}}
- No code generation is required.{{sfn|Walls|2016|loc=§1.1.3|p=7}}
- No XML configuration is required.{{sfn|Walls|2016|loc=§Preface|p=x}}
- Optional support for Kotlin and Apache Groovy in addition to Java.{{cite web |title=Language Support |url=https://docs.spring.io/spring-framework/reference/languages.html |website=Spring Framework}}
Bootstrapping DispatcherServlet
{{See also|Spring Framework#Configuration of DispatcherServlet}}
Spring Boot does not require manual configuration of the {{code|DispatcherServlet}}, since it automatically configures the application based on the configuration it detects. {{sfn|Deinum|Cosmina|2021|loc=§2 Spring Framework Fundamentals - Spring Boot|pp=52-54}}
=SpringBootServletInitializer=
Spring Boot has a class {{code|SpringBootServletInitializer}}, which is a specialization of the {{code|WebApplicationInitializer}}.{{sfn|Deinum|Cosmina|2021|loc=§2 Spring Framework Fundamentals - Spring Boot|pp=52-54}} This {{code|SpringBootServletInitializer}} is an out-of-the-box implementation of {{code|WebApplicationInitializer}}, which eliminates the need for the developer to construct their own implementation of the {{code|WebApplicationInitializer}} class.{{sfn|Deinum|Cosmina|2021|loc=§2 Spring Framework Fundamentals - Spring Boot|pp=52-54}}
Configuration properties
The configuration properties for the Spring Boot application can be specified in the {{code|application.properties}} or {{code|application.yml}} file.{{sfn|Deinum|Cosmina|2021|loc=§2 Spring Framework Fundamentals - Spring Boot|pp=52-54}}
Examples of properties that can be included in this file include the server.port
and spring.application.name
properties.{{sfn|Deinum|Cosmina|2021|loc=§2 Spring Framework Fundamentals - Spring Boot|pp=52-54}}
Autoconfiguration
=@SpringBootApplication=
Spring boot has an annotation, {{code|@SpringBootApplication}}, which allows the Spring Boot application to autoconfigure third-party libraries and detected features found on the classpath.{{sfn|Deinum|Cosmina|2021|loc=§2 Spring Framework Fundamentals - Spring Boot|pp=52-54}} As an example, the class that has the {{code|@SpringBootApplication}} annotation can extend the {{code|SpringBootServerInitializer}} class if the application is packaged and deployed as a WAR file.{{sfn|Deinum|Cosmina|2021|loc=§2 Spring Framework Fundamentals - Spring Boot|pp=52-54}}
The {{code|@SpringBootApplication}} annotation combines three Spring-specific annotations: {{code|@SpringBootConfiguration}}, {{code|@EnableAutoConfiguration}} and {{code|@ComponentScan}}.{{sfn|Walls|2019|loc=§1.2.2 Examining the Spring project structure|pp=11-17}}
==@SpringBootConfiguration==
The {{code|@SpringBootConfiguration}} annotation is a specialization of the Spring-specific {{code|@Configuration}} annotation.{{sfn|Walls|2019|loc=§1.2.2 Examining the Spring project structure|pp=11-17}} The class with the {{code|@SpringBootConfiguration}} is marked as the configuration class for the Spring Boot application.{{sfn|Walls|2019|loc=§1.2.2 Examining the Spring project structure|pp=11-17}}
==@EnableAutoConfiguration==
The {{code|@EnableAutoConfiguration}} annotation is Spring-specific annotation that enables the Spring Boot automatic configuration. {{sfn|Walls|2019|loc=§1.2.2 Examining the Spring project structure|pp=11-17}}
Actuator
The Spring Boot Actuator allows for monitoring and management capabilities for the Spring Boot Application.{{sfn|Musib|2022|loc=§4.4 Spring Boot Actuator|pp=144-145}} A major advantage of using the Spring Boot Actuator is that it implements a number of production-ready features without requiring the developer to construct their own implementations.{{sfn|Musib|2022|loc=§4.4 Spring Boot Actuator|pp=144-145}}
If Maven is used as the build tool, then the {{code|spring-boot-starter-actuator}} dependency can be specified in the pom.xml
configuration file.{{sfn|Musib|2022|loc=§4.4.1 Configuring Spring Boot Actuator in a Spring Boot application|pp=145-146}}
Integration with Spring Framework Modules
Spring Boot has a number of existing Spring Framework Modules.
=Spring Security=
{{main article|Spring Security}}
Spring Boot has integration with the Spring Security Module. The simplest way for integrating Spring Boot with Spring Security is to declare the starter dependency in the build configuration file.{{sfn|Musib|2022|loc=§5.2.1 Configuring Spring Boot Actuator in a Spring Boot application|pp=187-192}}
If Maven is used as the build tool, then the dependency with artifact ID {{code|spring-boot-starter-security}} dependency can be specified in the pom.xml
configuration file.{{sfn|Musib|2022|loc=§5.2.1 Configuring Spring Boot Actuator in a Spring Boot application|pp=187-192}}
Application servers
By default, Spring boot provides embedded web servers (such as Tomcat) out-of-the-box.{{sfn|Musib|2022|loc=§1.1.4 Spring Boot components|pp=7-8}} However, Spring Boot can also be deployed as a WAR file on a standalone WildFly application server.{{sfn|Musib|2022|loc=§9.2 Deploying Spring Boot application as WAR in the wildfly application server|pp=406-417}}
If Maven is used as the build tool, there is a {{code|wildfly-maven-plugin}} Maven plugin that allows for automatic deployment of the generated WAR file.{{sfn|Musib|2022|loc=§9.2 Deploying Spring Boot application as WAR in the wildfly application server|pp=406-417}}
References
{{Reflist}}
- {{cite book|last1=Deinum|first1=Marten|last2=Cosmina|first2=Iuliana|title=Pro Spring MVC with WebFlux|publisher=Apress|publication-place=Berkeley, CA|year=2021|isbn=978-1-4842-5665-7|doi=10.1007/978-1-4842-5666-4|s2cid=231672329}}
- {{cite book|last=Musib|first=Somnath|title=Spring Boot in Practice|publisher=Simon and Schuster|date=July 12, 2022|isbn=978-1-61729-881-3}}
- {{cite book|last=Walls|first=Craig|title=Spring Boot in Action|publisher=Manning|date=Jan 3, 2016|isbn=978-1-61729-254-5}}
- {{cite book|last=Walls|first=Craig|title=Spring in Action|publisher=Manning|date=2019|isbn=978-1-61729-494-5}}
External links
{{Wikibooks|Java Programming|Spring Boot}}
- {{Official website|https://spring.io/}}
{{Java (Sun)}}
{{Authority control}}
Category:Aspect-oriented programming