Download Spring Boot Reference Guide - Spring Documentation PDF

TitleSpring Boot Reference Guide - Spring Documentation
LanguageEnglish
File Size11.5 MB
Total Pages534
Table of Contents
                            Spring Boot Reference Documentation
Table of Contents
Legal
Chapter 1. Spring Boot Documentation
	1.1. About the Documentation
	1.2. Getting Help
	1.3. First Steps
	1.4. Working with Spring Boot
	1.5. Learning about Spring Boot Features
	1.6. Moving to Production
	1.7. Advanced Topics
Chapter 2. Getting Started
	2.1. Introducing Spring Boot
	2.2. System Requirements
		2.2.1. Servlet Containers
	2.3. Installing Spring Boot
		2.3.1. Installation Instructions for the Java Developer
			Maven Installation
			Gradle Installation
		2.3.2. Installing the Spring Boot CLI
			Manual Installation
			Installation with SDKMAN!
			OSX Homebrew Installation
			MacPorts Installation
			Command-line Completion
			Windows Scoop Installation
			Quick-start Spring CLI Example
		2.3.3. Upgrading from an Earlier Version of Spring Boot
	2.4. Developing Your First Spring Boot Application
		2.4.1. Creating the POM
		2.4.2. Adding Classpath Dependencies
		2.4.3. Writing the Code
			The @RestController and @RequestMapping Annotations
			The @EnableAutoConfiguration Annotation
			The “main” Method
		2.4.4. Running the Example
		2.4.5. Creating an Executable Jar
	2.5. What to Read Next
Chapter 3. Using Spring Boot
	3.1. Build Systems
		3.1.1. Dependency Management
		3.1.2. Maven
		3.1.3. Gradle
		3.1.4. Ant
		3.1.5. Starters
	3.2. Structuring Your Code
		3.2.1. Using the “default” Package
		3.2.2. Locating the Main Application Class
	3.3. Configuration Classes
		3.3.1. Importing Additional Configuration Classes
		3.3.2. Importing XML Configuration
	3.4. Auto-configuration
		3.4.1. Gradually Replacing Auto-configuration
		3.4.2. Disabling Specific Auto-configuration Classes
	3.5. Spring Beans and Dependency Injection
	3.6. Using the @SpringBootApplication Annotation
	3.7. Running Your Application
		3.7.1. Running from an IDE
		3.7.2. Running as a Packaged Application
		3.7.3. Using the Maven Plugin
		3.7.4. Using the Gradle Plugin
		3.7.5. Hot Swapping
	3.8. Developer Tools
		3.8.1. Property Defaults
		3.8.2. Automatic Restart
			Logging changes in condition evaluation
			Excluding Resources
			Watching Additional Paths
			Disabling Restart
			Using a Trigger File
			Customizing the Restart Classloader
			Known Limitations
		3.8.3. LiveReload
		3.8.4. Global Settings
			Configuring File System Watcher
		3.8.5. Remote Applications
			Running the Remote Client Application
			Remote Update
	3.9. Packaging Your Application for Production
	3.10. What to Read Next
Chapter 4. Spring Boot Features
	4.1. SpringApplication
		4.1.1. Startup Failure
		4.1.2. Lazy Initialization
		4.1.3. Customizing the Banner
		4.1.4. Customizing SpringApplication
		4.1.5. Fluent Builder API
		4.1.6. Application Availability
			Liveness State
			Readiness State
			Managing the Application Availability State
		4.1.7. Application Events and Listeners
		4.1.8. Web Environment
		4.1.9. Accessing Application Arguments
		4.1.10. Using the ApplicationRunner or CommandLineRunner
		4.1.11. Application Exit
		4.1.12. Admin Features
	4.2. Externalized Configuration
		4.2.1. Configuring Random Values
		4.2.2. Accessing Command Line Properties
		4.2.3. Application Property Files
		4.2.4. Profile-specific Properties
		4.2.5. Placeholders in Properties
		4.2.6. Encrypting Properties
		4.2.7. Using YAML Instead of Properties
			Loading YAML
			Exposing YAML as Properties in the Spring Environment
			Multi-profile YAML Documents
			YAML Shortcomings
		4.2.8. Type-safe Configuration Properties
			JavaBean properties binding
			Constructor binding
			Enabling @ConfigurationProperties-annotated types
			Using @ConfigurationProperties-annotated types
			Third-party Configuration
			Relaxed Binding
			Merging Complex Types
			Properties Conversion
			@ConfigurationProperties Validation
			@ConfigurationProperties vs. @Value
	4.3. Profiles
		4.3.1. Adding Active Profiles
		4.3.2. Programmatically Setting Profiles
		4.3.3. Profile-specific Configuration Files
	4.4. Logging
		4.4.1. Log Format
		4.4.2. Console Output
			Color-coded Output
		4.4.3. File Output
		4.4.4. Log Levels
		4.4.5. Log Groups
		4.4.6. Custom Log Configuration
		4.4.7. Logback Extensions
			Profile-specific Configuration
			Environment Properties
	4.5. Internationalization
	4.6. JSON
		4.6.1. Jackson
		4.6.2. Gson
		4.6.3. JSON-B
	4.7. Developing Web Applications
		4.7.1. The “Spring Web MVC Framework”
			Spring MVC Auto-configuration
			HttpMessageConverters
			Custom JSON Serializers and Deserializers
			MessageCodesResolver
			Static Content
			Welcome Page
			Custom Favicon
			Path Matching and Content Negotiation
			ConfigurableWebBindingInitializer
			Template Engines
			Error Handling
			Spring HATEOAS
			CORS Support
		4.7.2. The “Spring WebFlux Framework”
			Spring WebFlux Auto-configuration
			HTTP Codecs with HttpMessageReaders and HttpMessageWriters
			Static Content
			Welcome Page
			Template Engines
			Error Handling
			Web Filters
		4.7.3. JAX-RS and Jersey
		4.7.4. Embedded Servlet Container Support
			Servlets, Filters, and listeners
			Servlet Context Initialization
			The ServletWebServerApplicationContext
			Customizing Embedded Servlet Containers
			JSP Limitations
		4.7.5. Embedded Reactive Server Support
		4.7.6. Reactive Server Resources Configuration
	4.8. Graceful shutdown
	4.9. RSocket
		4.9.1. RSocket Strategies Auto-configuration
		4.9.2. RSocket server Auto-configuration
		4.9.3. Spring Messaging RSocket support
		4.9.4. Calling RSocket Services with RSocketRequester
	4.10. Security
		4.10.1. MVC Security
		4.10.2. WebFlux Security
		4.10.3. OAuth2
			Client
			Resource Server
			Authorization Server
		4.10.4. SAML 2.0
			Relying Party
		4.10.5. Actuator Security
			Cross Site Request Forgery Protection
	4.11. Working with SQL Databases
		4.11.1. Configure a DataSource
			Embedded Database Support
			Connection to a Production Database
			Connection to a JNDI DataSource
		4.11.2. Using JdbcTemplate
		4.11.3. JPA and Spring Data JPA
			Entity Classes
			Spring Data JPA Repositories
			Creating and Dropping JPA Databases
			Open EntityManager in View
		4.11.4. Spring Data JDBC
		4.11.5. Using H2’s Web Console
			Changing the H2 Console’s Path
		4.11.6. Using jOOQ
			Code Generation
			Using DSLContext
			jOOQ SQL Dialect
			Customizing jOOQ
		4.11.7. Using R2DBC
			Embedded Database Support
			Using DatabaseClient
			Spring Data R2DBC Repositories
	4.12. Working with NoSQL Technologies
		4.12.1. Redis
			Connecting to Redis
		4.12.2. MongoDB
			Connecting to a MongoDB Database
			MongoTemplate
			Spring Data MongoDB Repositories
			Embedded Mongo
		4.12.3. Neo4j
			Connecting to a Neo4j Database
			Using the Embedded Mode
			Using Native Types
			Neo4jSession
			Spring Data Neo4j Repositories
		4.12.4. Solr
			Connecting to Solr
			Spring Data Solr Repositories
		4.12.5. Elasticsearch
			Connecting to Elasticsearch using REST clients
			Connecting to Elasticsearch using Reactive REST clients
			Connecting to Elasticsearch by Using Spring Data
			Spring Data Elasticsearch Repositories
		4.12.6. Cassandra
			Connecting to Cassandra
			Spring Data Cassandra Repositories
		4.12.7. Couchbase
			Connecting to Couchbase
			Spring Data Couchbase Repositories
		4.12.8. LDAP
			Connecting to an LDAP Server
			Spring Data LDAP Repositories
			Embedded In-memory LDAP Server
		4.12.9. InfluxDB
			Connecting to InfluxDB
	4.13. Caching
		4.13.1. Supported Cache Providers
			Generic
			JCache (JSR-107)
			EhCache 2.x
			Hazelcast
			Infinispan
			Couchbase
			Redis
			Caffeine
			Simple
			None
	4.14. Messaging
		4.14.1. JMS
			ActiveMQ Support
			Artemis Support
			Using a JNDI ConnectionFactory
			Sending a Message
			Receiving a Message
		4.14.2. AMQP
			RabbitMQ support
			Sending a Message
			Receiving a Message
		4.14.3. Apache Kafka Support
			Sending a Message
			Receiving a Message
			Kafka Streams
			Additional Kafka Properties
			Testing with Embedded Kafka
	4.15. Calling REST Services with RestTemplate
		4.15.1. RestTemplate Customization
	4.16. Calling REST Services with WebClient
		4.16.1. WebClient Runtime
		4.16.2. WebClient Customization
	4.17. Validation
	4.18. Sending Email
	4.19. Distributed Transactions with JTA
		4.19.1. Using an Atomikos Transaction Manager
		4.19.2. Using a Bitronix Transaction Manager
		4.19.3. Using a Java EE Managed Transaction Manager
		4.19.4. Mixing XA and Non-XA JMS Connections
		4.19.5. Supporting an Alternative Embedded Transaction Manager
	4.20. Hazelcast
	4.21. Quartz Scheduler
	4.22. Task Execution and Scheduling
	4.23. Spring Integration
	4.24. Spring Session
	4.25. Monitoring and Management over JMX
	4.26. Testing
		4.26.1. Test Scope Dependencies
		4.26.2. Testing Spring Applications
		4.26.3. Testing Spring Boot Applications
			Detecting Web Application Type
			Detecting Test Configuration
			Excluding Test Configuration
			Using Application Arguments
			Testing with a mock environment
			Testing with a running server
			Customizing WebTestClient
			Using JMX
			Mocking and Spying Beans
			Auto-configured Tests
			Auto-configured JSON Tests
			Auto-configured Spring MVC Tests
			Auto-configured Spring WebFlux Tests
			Auto-configured Data JPA Tests
			Auto-configured JDBC Tests
			Auto-configured Data JDBC Tests
			Auto-configured jOOQ Tests
			Auto-configured Data MongoDB Tests
			Auto-configured Data Neo4j Tests
			Auto-configured Data Redis Tests
			Auto-configured Data LDAP Tests
			Auto-configured REST Clients
			Auto-configured Spring REST Docs Tests
			Auto-configured Spring Web Services Tests
			Additional Auto-configuration and Slicing
			User Configuration and Slicing
			Using Spock to Test Spring Boot Applications
		4.26.4. Test Utilities
			ConfigFileApplicationContextInitializer
			TestPropertyValues
			OutputCapture
			TestRestTemplate
	4.27. WebSockets
	4.28. Web Services
		4.28.1. Calling Web Services with WebServiceTemplate
	4.29. Creating Your Own Auto-configuration
		4.29.1. Understanding Auto-configured Beans
		4.29.2. Locating Auto-configuration Candidates
		4.29.3. Condition Annotations
			Class Conditions
			Bean Conditions
			Property Conditions
			Resource Conditions
			Web Application Conditions
			SpEL Expression Conditions
		4.29.4. Testing your Auto-configuration
			Simulating a Web Context
			Overriding the Classpath
		4.29.5. Creating Your Own Starter
			Naming
			Configuration keys
			The “autoconfigure” Module
			Starter Module
	4.30. Kotlin support
		4.30.1. Requirements
		4.30.2. Null-safety
		4.30.3. Kotlin API
			runApplication
			Extensions
		4.30.4. Dependency management
		4.30.5. @ConfigurationProperties
		4.30.6. Testing
		4.30.7. Resources
			Further reading
			Examples
	4.31. Building Docker Images
		4.31.1. Layering Docker Images
		4.31.2. Writing the Dockerfile
		4.31.3. Buildpacks
	4.32. What to Read Next
Chapter 5. Spring Boot Actuator: Production-ready Features
	5.1. Enabling Production-ready Features
	5.2. Endpoints
		5.2.1. Enabling Endpoints
		5.2.2. Exposing Endpoints
		5.2.3. Securing HTTP Endpoints
		5.2.4. Configuring Endpoints
		5.2.5. Hypermedia for Actuator Web Endpoints
		5.2.6. CORS Support
		5.2.7. Implementing Custom Endpoints
			Receiving Input
			Custom Web Endpoints
			Servlet endpoints
			Controller endpoints
		5.2.8. Health Information
			Auto-configured HealthIndicators
			Writing Custom HealthIndicators
			Reactive Health Indicators
			Auto-configured ReactiveHealthIndicators
			Health Groups
		5.2.9. Kubernetes Probes
			Checking external state with Kubernetes Probes
			Application lifecycle and Probes states
		5.2.10. Application Information
			Auto-configured InfoContributors
			Custom Application Information
			Git Commit Information
			Build Information
			Writing Custom InfoContributors
	5.3. Monitoring and Management over HTTP
		5.3.1. Customizing the Management Endpoint Paths
		5.3.2. Customizing the Management Server Port
		5.3.3. Configuring Management-specific SSL
		5.3.4. Customizing the Management Server Address
		5.3.5. Disabling HTTP Endpoints
	5.4. Monitoring and Management over JMX
		5.4.1. Customizing MBean Names
		5.4.2. Disabling JMX Endpoints
		5.4.3. Using Jolokia for JMX over HTTP
			Customizing Jolokia
			Disabling Jolokia
	5.5. Loggers
		5.5.1. Configure a Logger
	5.6. Metrics
		5.6.1. Getting started
		5.6.2. Supported monitoring systems
			AppOptics
			Atlas
			Datadog
			Dynatrace
			Elastic
			Ganglia
			Graphite
			Humio
			Influx
			JMX
			KairosDB
			New Relic
			Prometheus
			SignalFx
			Simple
			Stackdriver
			StatsD
			Wavefront
		5.6.3. Supported Metrics
			Spring MVC Metrics
			Spring WebFlux Metrics
			Jersey Server Metrics
			HTTP Client Metrics
			Cache Metrics
			DataSource Metrics
			Hibernate Metrics
			RabbitMQ Metrics
		5.6.4. Registering custom metrics
		5.6.5. Customizing individual metrics
			Common tags
			Per-meter properties
		5.6.6. Metrics endpoint
	5.7. Auditing
		5.7.1. Custom Auditing
	5.8. HTTP Tracing
		5.8.1. Custom HTTP tracing
	5.9. Process Monitoring
		5.9.1. Extending Configuration
		5.9.2. Programmatically
	5.10. Cloud Foundry Support
		5.10.1. Disabling Extended Cloud Foundry Actuator Support
		5.10.2. Cloud Foundry Self-signed Certificates
		5.10.3. Custom context path
	5.11. What to Read Next
Chapter 6. Deploying Spring Boot Applications
	6.1. Deploying to Containers
	6.2. Deploying to the Cloud
		6.2.1. Cloud Foundry
			Binding to Services
		6.2.2. Kubernetes
			Kubernetes Container Lifecycle
		6.2.3. Heroku
		6.2.4. OpenShift
		6.2.5. Amazon Web Services (AWS)
			AWS Elastic Beanstalk
			Summary
		6.2.6. Boxfuse and Amazon Web Services
		6.2.7. Google Cloud
	6.3. Installing Spring Boot Applications
		6.3.1. Supported Operating Systems
		6.3.2. Unix/Linux Services
			Installation as an init.d Service (System V)
			Installation as a systemd Service
			Customizing the Startup Script
		6.3.3. Microsoft Windows Services
	6.4. What to Read Next
Chapter 7. Spring Boot CLI
	7.1. Installing the CLI
	7.2. Using the CLI
		7.2.1. Running Applications with the CLI
			Deduced “grab” Dependencies
			Deduced “grab” Coordinates
			Default Import Statements
			Automatic Main Method
			Custom Dependency Management
		7.2.2. Applications with Multiple Source Files
		7.2.3. Packaging Your Application
		7.2.4. Initialize a New Project
		7.2.5. Using the Embedded Shell
		7.2.6. Adding Extensions to the CLI
	7.3. Developing Applications with the Groovy Beans DSL
	7.4. Configuring the CLI with settings.xml
	7.5. What to Read Next
Chapter 8. Build Tool Plugins
	8.1. Spring Boot Maven Plugin
	8.2. Spring Boot Gradle Plugin
	8.3. Spring Boot AntLib Module
		8.3.1. Spring Boot Ant Tasks
			Using the “exejar” Task
			Examples
		8.3.2. Using the “findmainclass” Task
			Examples
	8.4. Supporting Other Build Systems
		8.4.1. Repackaging Archives
		8.4.2. Nested Libraries
		8.4.3. Finding a Main Class
		8.4.4. Example Repackage Implementation
	8.5. What to Read Next
Chapter 9. “How-to” Guides
	9.1. Spring Boot Application
		9.1.1. Create Your Own FailureAnalyzer
		9.1.2. Troubleshoot Auto-configuration
		9.1.3. Customize the Environment or ApplicationContext Before It Starts
		9.1.4. Build an ApplicationContext Hierarchy (Adding a Parent or Root Context)
		9.1.5. Create a Non-web Application
	9.2. Properties and Configuration
		9.2.1. Automatically Expand Properties at Build Time
			Automatic Property Expansion Using Maven
			Automatic Property Expansion Using Gradle
		9.2.2. Externalize the Configuration of SpringApplication
		9.2.3. Change the Location of External Properties of an Application
		9.2.4. Use ‘Short’ Command Line Arguments
		9.2.5. Use YAML for External Properties
		9.2.6. Set the Active Spring Profiles
		9.2.7. Change Configuration Depending on the Environment
		9.2.8. Discover Built-in Options for External Properties
	9.3. Embedded Web Servers
		9.3.1. Use Another Web Server
		9.3.2. Disabling the Web Server
		9.3.3. Change the HTTP Port
		9.3.4. Use a Random Unassigned HTTP Port
		9.3.5. Discover the HTTP Port at Runtime
		9.3.6. Enable HTTP Response Compression
		9.3.7. Configure SSL
		9.3.8. Configure HTTP/2
			HTTP/2 with Undertow
			HTTP/2 with Jetty
			HTTP/2 with Tomcat
			HTTP/2 with Reactor Netty
		9.3.9. Configure the Web Server
		9.3.10. Add a Servlet, Filter, or Listener to an Application
			Add a Servlet, Filter, or Listener by Using a Spring Bean
			Add Servlets, Filters, and Listeners by Using Classpath Scanning
		9.3.11. Configure Access Logging
		9.3.12. Running Behind a Front-end Proxy Server
			Customize Tomcat’s Proxy Configuration
		9.3.13. Enable Multiple Connectors with Tomcat
		9.3.14. Use Tomcat’s LegacyCookieProcessor
		9.3.15. Enable Tomcat’s MBean Registry
		9.3.16. Enable Multiple Listeners with Undertow
		9.3.17. Create WebSocket Endpoints Using @ServerEndpoint
	9.4. Spring MVC
		9.4.1. Write a JSON REST Service
		9.4.2. Write an XML REST Service
		9.4.3. Customize the Jackson ObjectMapper
		9.4.4. Customize the @ResponseBody Rendering
		9.4.5. Handling Multipart File Uploads
		9.4.6. Switch Off the Spring MVC DispatcherServlet
		9.4.7. Switch off the Default MVC Configuration
		9.4.8. Customize ViewResolvers
	9.5. Testing With Spring Security
	9.6. Jersey
		9.6.1. Secure Jersey endpoints with Spring Security
		9.6.2. Use Jersey Alongside Another Web Framework
	9.7. HTTP Clients
		9.7.1. Configure RestTemplate to Use a Proxy
		9.7.2. Configure the TcpClient used by a Reactor Netty-based WebClient
	9.8. Logging
		9.8.1. Configure Logback for Logging
			Configure Logback for File-only Output
		9.8.2. Configure Log4j for Logging
			Use YAML or JSON to Configure Log4j 2
	9.9. Data Access
		9.9.1. Configure a Custom DataSource
		9.9.2. Configure Two DataSources
		9.9.3. Use Spring Data Repositories
		9.9.4. Separate @Entity Definitions from Spring Configuration
		9.9.5. Configure JPA Properties
		9.9.6. Configure Hibernate Naming Strategy
		9.9.7. Configure Hibernate Second-Level Caching
		9.9.8. Use Dependency Injection in Hibernate Components
		9.9.9. Use a Custom EntityManagerFactory
		9.9.10. Use Two EntityManagers
		9.9.11. Use a Traditional persistence.xml File
		9.9.12. Use Spring Data JPA and Mongo Repositories
		9.9.13. Customize Spring Data’s Web Support
		9.9.14. Expose Spring Data Repositories as REST Endpoint
		9.9.15. Configure a Component that is Used by JPA
		9.9.16. Configure jOOQ with Two DataSources
	9.10. Database Initialization
		9.10.1. Initialize a Database Using JPA
		9.10.2. Initialize a Database Using Hibernate
		9.10.3. Initialize a Database using basic SQL scripts
		9.10.4. Initialize a Database Using R2DBC
		9.10.5. Initialize a Spring Batch Database
		9.10.6. Use a Higher-level Database Migration Tool
			Execute Flyway Database Migrations on Startup
			Execute Liquibase Database Migrations on Startup
	9.11. Messaging
		9.11.1. Disable Transacted JMS Session
	9.12. Batch Applications
		9.12.1. Specifying a Batch Data Source
		9.12.2. Running Spring Batch Jobs on Startup
		9.12.3. Running from the Command Line
		9.12.4. Storing the Job Repository
	9.13. Actuator
		9.13.1. Change the HTTP Port or Address of the Actuator Endpoints
		9.13.2. Customize the ‘whitelabel’ Error Page
		9.13.3. Sanitize Sensitive Values
		9.13.4. Map Health Indicators to Micrometer Metrics
	9.14. Security
		9.14.1. Switch off the Spring Boot Security Configuration
		9.14.2. Change the UserDetailsService and Add User Accounts
		9.14.3. Enable HTTPS When Running behind a Proxy Server
	9.15. Hot Swapping
		9.15.1. Reload Static Content
		9.15.2. Reload Templates without Restarting the Container
			Thymeleaf Templates
			FreeMarker Templates
			Groovy Templates
		9.15.3. Fast Application Restarts
		9.15.4. Reload Java Classes without Restarting the Container
	9.16. Build
		9.16.1. Generate Build Information
		9.16.2. Generate Git Information
		9.16.3. Customize Dependency Versions
		9.16.4. Create an Executable JAR with Maven
		9.16.5. Use a Spring Boot Application as a Dependency
		9.16.6. Extract Specific Libraries When an Executable Jar Runs
		9.16.7. Create a Non-executable JAR with Exclusions
		9.16.8. Remote Debug a Spring Boot Application Started with Maven
		9.16.9. Build an Executable Archive from Ant without Using spring-boot-antlib
	9.17. Traditional Deployment
		9.17.1. Create a Deployable War File
		9.17.2. Convert an Existing Application to Spring Boot
		9.17.3. Deploying a WAR to WebLogic
		9.17.4. Use Jedis Instead of Lettuce
		9.17.5. Use Testcontainers for integration testing
Chapter 10. Appendices
	Appendix A: Common Application properties
		10.A.1. Core properties
		10.A.2. Cache properties
		10.A.3. Mail properties
		10.A.4. JSON properties
		10.A.5. Data properties
		10.A.6. Transaction properties
		10.A.7. Data migration properties
		10.A.8. Integration properties
		10.A.9. Web properties
		10.A.10. Templating properties
		10.A.11. Server properties
		10.A.12. Security properties
		10.A.13. RSocket properties
		10.A.14. Actuator properties
		10.A.15. Devtools properties
		10.A.16. Testing properties
	Appendix B: Configuration Metadata
		10.B.1. Metadata Format
			Group Attributes
			Property Attributes
			Hint Attributes
			Repeated Metadata Items
		10.B.2. Providing Manual Hints
			Value Hint
			Value Providers
		10.B.3. Generating Your Own Metadata by Using the Annotation Processor
			Nested Properties
			Adding Additional Metadata
	Appendix C: Auto-configuration Classes
		10.C.1. spring-boot-autoconfigure
		10.C.2. spring-boot-actuator-autoconfigure
	Appendix D: Test Auto-configuration Annotations
		10.D.1. Test Slices
	Appendix E: The Executable Jar Format
		10.E.1. Nested JARs
			The Executable Jar File Structure
			The Executable War File Structure
			Index Files
			Classpath Index
			Layer Index
		10.E.2. Spring Boot’s “JarFile” Class
			Compatibility with the Standard Java “JarFile”
		10.E.3. Launching Executable Jars
			Launcher Manifest
		10.E.4. PropertiesLauncher Features
		10.E.5. Executable Jar Restrictions
		10.E.6. Alternative Single Jar Solutions
	Appendix F: Dependency versions
		10.F.1. Managed Dependency Coordinates
		10.F.2. Version Properties
                        
Document Text Contents
Page 1

Spring Boot Reference Documentation
Phillip Webb, Dave Syer, Josh Long, Stéphane Nicoll, Rob Winch, Andy

Wilkinson, Marcel Overdijk, Christian Dupuis, Sébastien Deleuze, Michael
Simons, Vedran Pavić, Jay Bryant, Madhura Bhave, Eddú Meléndez, Scott

Frederick

Page 2

Table of Contents
Legal. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  1

1. Spring Boot Documentation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  2

1.1. About the Documentation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  2

1.2. Getting Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  2

1.3. First Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  2

1.4. Working with Spring Boot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  2

1.5. Learning about Spring Boot Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  3

1.6. Moving to Production . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  3

1.7. Advanced Topics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  3

2. Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  4

2.1. Introducing Spring Boot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  4

2.2. System Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  4

2.2.1. Servlet Containers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  4

2.3. Installing Spring Boot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  5

2.3.1. Installation Instructions for the Java Developer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  5

Maven Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  5

Gradle Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  6

2.3.2. Installing the Spring Boot CLI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  6

Manual Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  6

Installation with SDKMAN!. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  6

OSX Homebrew Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  7

MacPorts Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  8

Command-line Completion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  8

Windows Scoop Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  8

Quick-start Spring CLI Example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  8

2.3.3. Upgrading from an Earlier Version of Spring Boot. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  9

2.4. Developing Your First Spring Boot Application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  10

2.4.1. Creating the POM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  10

2.4.2. Adding Classpath Dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  12

2.4.3. Writing the Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  12

The @RestController and @RequestMapping Annotations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  13

The @EnableAutoConfiguration Annotation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  13

The “main” Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  14

2.4.4. Running the Example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  14

2.4.5. Creating an Executable Jar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  14

2.5. What to Read Next . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  17

3. Using Spring Boot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  18

3.1. Build Systems. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  18

Page 267

Spring Boot also configures built-in instrumentation (i.e. MeterBinder implementations) that you can
control via configuration or dedicated annotation markers.

5.6.2. Supported monitoring systems

AppOptics

By default, the AppOptics registry pushes metrics to api.appoptics.com/v1/measurements periodically.
To export metrics to SaaS AppOptics, your API token must be provided:

management.metrics.export.appoptics.api-token=YOUR_TOKEN

Atlas

By default, metrics are exported to Atlas running on your local machine. The location of the Atlas
server to use can be provided using:

management.metrics.export.atlas.uri=https://atlas.example.com:7101/api/v1/publish

Datadog

Datadog registry pushes metrics to datadoghq periodically. To export metrics to Datadog, your API
key must be provided:

management.metrics.export.datadog.api-key=YOUR_KEY

You can also change the interval at which metrics are sent to Datadog:

management.metrics.export.datadog.step=30s

Dynatrace

Dynatrace registry pushes metrics to the configured URI periodically. To export metrics to
Dynatrace, your API token, device ID, and URI must be provided:

management.metrics.export.dynatrace.api-token=YOUR_TOKEN
management.metrics.export.dynatrace.device-id=YOUR_DEVICE_ID
management.metrics.export.dynatrace.uri=YOUR_URI

You can also change the interval at which metrics are sent to Dynatrace:

management.metrics.export.dynatrace.step=30s

249

https://api.appoptics.com/v1/measurements
https://micrometer.io/docs/registry/appoptics
https://micrometer.io/docs/registry/atlas
https://github.com/Netflix/atlas
https://github.com/Netflix/atlas
https://www.datadoghq.com

Page 268

Elastic

By default, metrics are exported to Elastic running on your local machine. The location of the
Elastic server to use can be provided using the following property:

management.metrics.export.elastic.host=https://elastic.example.com:8086

Ganglia

By default, metrics are exported to Ganglia running on your local machine. The Ganglia server host
and port to use can be provided using:

management.metrics.export.ganglia.host=ganglia.example.com
management.metrics.export.ganglia.port=9649

Graphite

By default, metrics are exported to Graphite running on your local machine. The Graphite server
host and port to use can be provided using:

management.metrics.export.graphite.host=graphite.example.com
management.metrics.export.graphite.port=9004

Micrometer provides a default HierarchicalNameMapper that governs how a dimensional meter id is
mapped to flat hierarchical names.

đ
To take control over this behaviour, define your GraphiteMeterRegistry and supply
your own HierarchicalNameMapper. An auto-configured GraphiteConfig and Clock
beans are provided unless you define your own:

@Bean
public GraphiteMeterRegistry graphiteMeterRegistry(GraphiteConfig config, Clock clock)
{
  return new GraphiteMeterRegistry(config, clock, MY_HIERARCHICAL_MAPPER);
}

Humio

By default, the Humio registry pushes metrics to cloud.humio.com periodically. To export metrics to
SaaS Humio, your API token must be provided:

management.metrics.export.humio.api-token=YOUR_TOKEN

You should also configure one or more tags to identify the data source to which metrics will be

250

Page 533

Library Version Property

Maven Invoker Plugin maven-invoker-plugin.version

Maven Jar Plugin maven-jar-plugin.version

Maven Javadoc Plugin maven-javadoc-plugin.version

Maven Resources Plugin maven-resources-plugin.version

Maven Shade Plugin maven-shade-plugin.version

Maven Source Plugin maven-source-plugin.version

Maven Surefire Plugin maven-surefire-plugin.version

Maven War Plugin maven-war-plugin.version

Micrometer micrometer.version

MIMEPull mimepull.version

Mockito mockito.version

MongoDB mongodb.version

MSSQL JDBC mssql-jdbc.version

MySQL mysql.version

NekoHTML nekohtml.version

Neo4j OGM neo4j-ogm.version

Netty netty.version

Netty tcNative netty-tcnative.version

NIO Multipart Parser nio-multipart-parser.version

OAuth2 OIDC SDK oauth2-oidc-sdk.version

OJDBC ojdbc.version

OkHttp3 okhttp3.version

Pooled JMS pooled-jms.version

Postgresql postgresql.version

Prometheus PushGateway prometheus-pushgateway.version

Quartz quartz.version

QueryDSL querydsl.version

R2DBC Bom r2dbc-bom.version

Rabbit AMQP Client rabbit-amqp-client.version

Reactive Streams reactive-streams.version

Reactor Bom reactor-bom.version

REST Assured rest-assured.version

RSocket rsocket.version

RxJava rxjava.version

RxJava Adapter rxjava-adapter.version

RxJava2 rxjava2.version

SAAJ Impl saaj-impl.version

Selenium selenium.version

515

Page 534

Library Version Property

Selenium HtmlUnit selenium-htmlunit.version

SendGrid sendgrid.version

Servlet API servlet-api.version

SLF4J slf4j.version

SnakeYAML snakeyaml.version

Solr solr.version

Spring AMQP spring-amqp.version

Spring Batch spring-batch.version

Spring Boot spring-boot.version

Spring Data Releasetrain spring-data-releasetrain.version

Spring Framework spring-framework.version

Spring HATEOAS spring-hateoas.version

Spring Integration spring-integration.version

Spring Kafka spring-kafka.version

Spring LDAP spring-ldap.version

Spring RESTDocs spring-restdocs.version

Spring Retry spring-retry.version

Spring Security spring-security.version

Spring Session Bom spring-session-bom.version

Spring WS spring-ws.version

SQLite JDBC sqlite-jdbc.version

Sun Mail sun-mail.version

Thymeleaf thymeleaf.version

Thymeleaf Extras Data Attribute thymeleaf-extras-data-attribute.version

Thymeleaf Extras Java8Time thymeleaf-extras-java8time.version

Thymeleaf Extras SpringSecurity thymeleaf-extras-springsecurity.version

Thymeleaf Layout Dialect thymeleaf-layout-dialect.version

Tomcat tomcat.version

UnboundID LDAPSDK unboundid-ldapsdk.version

Undertow undertow.version

Versions Maven Plugin versions-maven-plugin.version

WebJars HAL Browser webjars-hal-browser.version

WebJars Locator Core webjars-locator-core.version

WSDL4j wsdl4j.version

XML Maven Plugin xml-maven-plugin.version

XmlUnit2 xmlunit2.version

516

Similer Documents