Spring Boot
Table of Contents
- Legal
- Spring Boot Documentation
- About the Documentation
- Getting Help
- First Steps
- Working with Spring Boot
- Learning about Spring Boot Features
- Moving to Production
- Advanced Topics
- Getting Started
- Introducing Spring Boot
- System Requirements
- Servlet Containers
- Installing Spring Boot
- Installation Instructions for the Java Developer
- Maven Installation
- Gradle Installation
- 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
- Upgrading from an Earlier Version of Spring Boot
- Installation Instructions for the Java Developer
- Developing Your First Spring Boot Application
- Creating the POM
- Adding Classpath Dependencies
- Writing the Code
- The @RestController and @RequestMapping Annotations
- The @EnableAutoConfiguration Annotation
- The “main” Method
- Running the Example
- Creating an Executable Jar
- What to Read Next
- Using Spring Boot
- Build Systems
- Dependency Management
- Maven
- Inheriting the Starter Parent
- Using Spring Boot without the Parent POM
- Using the Spring Boot Maven Plugin
- Gradle
- Ant
- Starters
- Structuring Your Code
- Using the “default” Package
- Locating the Main Application Class
- Configuration Classes
- Importing Additional Configuration Classes
- Importing XML Configuration
- Auto-configuration
- Gradually Replacing Auto-configuration
- Disabling Specific Auto-configuration Classes
- Spring Beans and Dependency Injection
- Using the @SpringBootApplication Annotation
- Running Your Application
- Running from an IDE
- Running as a Packaged Application
- Using the Maven Plugin
- Using the Gradle Plugin
- Hot Swapping
- Developer Tools
- Property Defaults
- Automatic Restart
- Logging changes in condition evaluation
- Excluding Resources
- Watching Additional Paths
- Disabling Restart
- Using a Trigger File
- Customizing the Restart Classloader
- Known Limitations
- LiveReload
- Global Settings
- Remote Applications
- Running the Remote Client Application
- Remote Update
- Configuring File System Watcher
- Packaging Your Application for Production
- What to Read Next
- Build Systems
- Spring Boot Features
- SpringApplication
- Startup Failure
- Lazy Initialization
- Customizing the Banner
- Customizing SpringApplication
- Fluent Builder API
- Application Events and Listeners
- Web Environment
- Accessing Application Arguments
- Using the ApplicationRunner or CommandLineRunner
- Application Exit
- Admin Features
- Externalized Configuration
- Configuring Random Values
- Accessing Command Line Properties
- Application Property Files
- Profile-specific Properties
- Placeholders in Properties
- Encrypting Properties
- Using YAML Instead of Properties
- Loading YAML
- Exposing YAML as Properties in the Spring Environment
- Multi-profile YAML Documents
- YAML Shortcomings
- 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
- Profiles
- Adding Active Profiles
- Programmatically Setting Profiles
- Profile-specific Configuration Files
- Logging
- Log Format
- Console Output
- Color-coded Output
- File Output
- Log Levels
- Log Groups
- Custom Log Configuration
- Logback Extensions
- Profile-specific Configuration
- Environment Properties
- Internationalization
- JSON
- Jackson
- Gson
- JSON-B
- Developing Web Applications
- 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
- The “Spring WebFlux Framework”
- Spring WebFlux Auto-configuration
- HTTP Codecs with HttpMessageReaders and HttpMessageWriters
- Static Content
- Template Engines
- Error Handling
- Web Filters
- JAX-RS and Jersey
- Embedded Servlet Container Support
- Servlets, Filters, and listeners
- Servlet Context Initialization
- The ServletWebServerApplicationContext
- Customizing Embedded Servlet Containers
- JSP Limitations
- Embedded Reactive Server Support
- Reactive Server Resources Configuration
- The “Spring Web MVC Framework”
- RSocket
- RSocket Strategies Auto-configuration
- RSocket server Auto-configuration
- Spring Messaging RSocket support
- Calling RSocket Services with RSocketRequester
- Security
- MVC Security
- WebFlux Security
- OAuth2
- Client
- Resource Server
- Authorization Server
- Actuator Security
- Cross Site Request Forgery Protection
- Working with SQL Databases
- Configure a DataSource
- Embedded Database Support
- Connection to a Production Database
- Connection to a JNDI DataSource
- Using JdbcTemplate
- JPA and Spring Data JPA
- Entity Classes
- Spring Data JPA Repositories
- Creating and Dropping JPA Databases
- Open EntityManager in View
- Spring Data JDBC
- Using H2’s Web Console
- Changing the H2 Console’s Path
- Using jOOQ
- Code Generation
- Using DSLContext
- jOOQ SQL Dialect
- Customizing jOOQ
- Configure a DataSource
- Working with NoSQL Technologies
- Redis
- Connecting to Redis
- MongoDB
- Connecting to a MongoDB Database
- MongoTemplate
- Spring Data MongoDB Repositories
- Embedded Mongo
- Neo4j
- Connecting to a Neo4j Database
- Using the Embedded Mode
- Using Native Types
- Neo4jSession
- Spring Data Neo4j Repositories
- Solr
- Connecting to Solr
- Spring Data Solr Repositories
- Elasticsearch
- Connecting to Elasticsearch using REST clients
- Connecting to Elasticsearch using Reactive REST clients
- Connecting to Elasticsearch using Jest
- Connecting to Elasticsearch by Using Spring Data
- Spring Data Elasticsearch Repositories
- Cassandra
- Connecting to Cassandra
- Spring Data Cassandra Repositories
- Couchbase
- Connecting to Couchbase
- Spring Data Couchbase Repositories
- LDAP
- Connecting to an LDAP Server
- Spring Data LDAP Repositories
- Embedded In-memory LDAP Server
- InfluxDB
- Connecting to InfluxDB
- Redis
- Caching
- Supported Cache Providers
- Generic
- JCache (JSR-107)
- EhCache 2.x
- Hazelcast
- Infinispan
- Couchbase
- Redis
- Caffeine
- Simple
- None
- Supported Cache Providers
- Messaging
- JMS
- ActiveMQ Support
- Artemis Support
- Using a JNDI ConnectionFactory
- Sending a Message
- Receiving a Message
- AMQP
- RabbitMQ support
- Sending a Message
- Receiving a Message
- Apache Kafka Support
- Sending a Message
- Receiving a Message
- Kafka Streams
- Additional Kafka Properties
- Testing with Embedded Kafka
- JMS
- Calling REST Services with RestTemplate
- RestTemplate Customization
- Calling REST Services with WebClient
- WebClient Runtime
- WebClient Customization
- Validation
- Sending Email
- Distributed Transactions with JTA
- Using an Atomikos Transaction Manager
- Using a Bitronix Transaction Manager
- Using a Java EE Managed Transaction Manager
- Mixing XA and Non-XA JMS Connections
- Supporting an Alternative Embedded Transaction Manager
- Hazelcast
- Quartz Scheduler
- Task Execution and Scheduling
- Spring Integration
- Spring Session
- Monitoring and Management over JMX
- Testing
- Test Scope Dependencies
- Testing Spring Applications
- 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
- 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
- Additional Auto-configuration and Slicing
- User Configuration and Slicing
- Using Spock to Test Spring Boot Applications
- Test Utilities
- ConfigFileApplicationContextInitializer
- TestPropertyValues
- OutputCapture
- TestRestTemplate
- WebSockets
- Web Services
- Calling Web Services with WebServiceTemplate
- Creating Your Own Auto-configuration
- Understanding Auto-configured Beans
- Locating Auto-configuration Candidates
- Condition Annotations
- Class Conditions
- Bean Conditions
- Property Conditions
- Resource Conditions
- Web Application Conditions
- SpEL Expression Conditions
- Testing your Auto-configuration
- Simulating a Web Context
- Overriding the Classpath
- Creating Your Own Starter
- Naming
- Configuration keys
- autoconfigure Module
- Starter Module
- Kotlin support
- Requirements
- Null-safety
- Kotlin API
- runApplication
- Extensions
- Dependency management
- @ConfigurationProperties
- Testing
- Resources
- Further reading
- Examples
- What to Read Next
- SpringApplication
- Spring Boot Actuator: Production-ready Features
- Enabling Production-ready Features
- Endpoints
- Enabling Endpoints
- Exposing Endpoints
- Securing HTTP Endpoints
- Configuring Endpoints
- Hypermedia for Actuator Web Endpoints
- CORS Support
- Implementing Custom Endpoints
- Receiving Input
- Custom Web Endpoints
- Servlet endpoints
- Controller endpoints
- Health Information
- Auto-configured HealthIndicators
- Writing Custom HealthIndicators
- Reactive Health Indicators
- Auto-configured ReactiveHealthIndicators
- Health Groups
- Application Information
- Auto-configured InfoContributors
- Custom Application Information
- Git Commit Information
- Build Information
- Writing Custom InfoContributors
- Monitoring and Management over HTTP
- Customizing the Management Endpoint Paths
- Customizing the Management Server Port
- Configuring Management-specific SSL
- Customizing the Management Server Address
- Disabling HTTP Endpoints
- Monitoring and Management over JMX
- Customizing MBean Names
- Disabling JMX Endpoints
- Using Jolokia for JMX over HTTP
- Customizing Jolokia
- Disabling Jolokia
- Loggers
- Configure a Logger
- Metrics
- Getting started
- Supported monitoring systems
- AppOptics
- Atlas
- Datadog
- Dynatrace
- Elastic
- Ganglia
- Graphite
- Humio
- Influx
- JMX
- KairosDB
- New Relic
- Prometheus
- SignalFx
- Simple
- StatsD
- Wavefront
- Supported Metrics
- Spring MVC Metrics
- Spring WebFlux Metrics
- Jersey Server Metrics
- HTTP Client Metrics
- Cache Metrics
- DataSource Metrics
- Hibernate Metrics
- RabbitMQ Metrics
- Registering custom metrics
- Customizing individual metrics
- Common tags
- Per-meter properties
- Metrics endpoint
- Auditing
- Custom Auditing
- HTTP Tracing
- Custom HTTP tracing
- Process Monitoring
- Extending Configuration
- Programmatically
- Cloud Foundry Support
- Disabling Extended Cloud Foundry Actuator Support
- Cloud Foundry Self-signed Certificates
- Custom context path
- What to Read Next
- Deploying Spring Boot Applications
- Deploying to the Cloud
- Cloud Foundry
- Binding to Services
- Heroku
- OpenShift
- Amazon Web Services (AWS)
- AWS Elastic Beanstalk
- Summary
- Boxfuse and Amazon Web Services
- Google Cloud
- Cloud Foundry
- Installing Spring Boot Applications
- Supported Operating Systems
- Unix/Linux Services
- Installation as an init.d Service (System V)
- Installation as a systemd Service
- Customizing the Startup Script
- Microsoft Windows Services
- What to Read Next
- Deploying to the Cloud
- Spring Boot CLI
- Installing the CLI
- Using the CLI
- Running Applications with the CLI
- Deduced “grab” Dependencies
- Deduced “grab” Coordinates
- Default Import Statements
- Automatic Main Method
- Custom Dependency Management
- Applications with Multiple Source Files
- Packaging Your Application
- Initialize a New Project
- Using the Embedded Shell
- Adding Extensions to the CLI
- Running Applications with the CLI
- Developing Applications with the Groovy Beans DSL
- Configuring the CLI with settings.xml
- What to Read Next
- Build Tool Plugins
- Spring Boot Maven Plugin
- Including the Plugin
- Packaging Executable Jar and War Files
- Spring Boot Gradle Plugin
- Spring Boot AntLib Module
- Spring Boot Ant Tasks
- spring-boot:exejar
- Examples
- spring-boot:findmainclass
- Examples
- Spring Boot Ant Tasks
- Supporting Other Build Systems
- Repackaging Archives
- Nested Libraries
- Finding a Main Class
- Example Repackage Implementation
- What to Read Next
- Spring Boot Maven Plugin
- “How-to” Guides
- Spring Boot Application
- Create Your Own FailureAnalyzer
- Troubleshoot Auto-configuration
- Customize the Environment or ApplicationContext Before It Starts
- Build an ApplicationContext Hierarchy (Adding a Parent or Root Context)
- Create a Non-web Application
- Properties and Configuration
- Automatically Expand Properties at Build Time
- Automatic Property Expansion Using Maven
- Automatic Property Expansion Using Gradle
- Externalize the Configuration of SpringApplication
- Change the Location of External Properties of an Application
- Use ‘Short’ Command Line Arguments
- Use YAML for External Properties
- Set the Active Spring Profiles
- Change Configuration Depending on the Environment
- Discover Built-in Options for External Properties
- Automatically Expand Properties at Build Time
- Embedded Web Servers
- Use Another Web Server
- Disabling the Web Server
- Change the HTTP Port
- Use a Random Unassigned HTTP Port
- Discover the HTTP Port at Runtime
- Enable HTTP Response Compression
- Configure SSL
- Configure HTTP/2
- HTTP/2 with Undertow
- HTTP/2 with Jetty
- HTTP/2 with Tomcat
- HTTP/2 with Reactor Netty
- Configure the Web Server
- 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
- Configure Access Logging
- Running Behind a Front-end Proxy Server
- Customize Tomcat’s Proxy Configuration
- Enable Multiple Connectors with Tomcat
- Use Tomcat’s LegacyCookieProcessor
- Enable Tomcat’s MBean Registry
- Enable Multiple Listeners with Undertow
- Create WebSocket Endpoints Using @ServerEndpoint
- Spring MVC
- Write a JSON REST Service
- Write an XML REST Service
- Customize the Jackson ObjectMapper
- Customize the @ResponseBody Rendering
- Handling Multipart File Uploads
- Switch Off the Spring MVC DispatcherServlet
- Switch off the Default MVC Configuration
- Customize ViewResolvers
- Testing With Spring Security
- Jersey
- Secure Jersey endpoints with Spring Security
- HTTP Clients
- Configure RestTemplate to Use a Proxy
- Configure the TcpClient used by a Reactor Netty-based WebClient
- Logging
- Configure Logback for Logging
- Configure Logback for File-only Output
- Configure Log4j for Logging
- Use YAML or JSON to Configure Log4j 2
- Configure Logback for Logging
- Data Access
- Configure a Custom DataSource
- Configure Two DataSources
- Use Spring Data Repositories
- Separate @Entity Definitions from Spring Configuration
- Configure JPA Properties
- Configure Hibernate Naming Strategy
- Configure Hibernate Second-Level Caching
- Use Dependency Injection in Hibernate Components
- Use a Custom EntityManagerFactory
- Use Two EntityManagers
- Use a Traditional persistence.xml File
- Use Spring Data JPA and Mongo Repositories
- Customize Spring Data’s Web Support
- Expose Spring Data Repositories as REST Endpoint
- Configure a Component that is Used by JPA
- Configure jOOQ with Two DataSources
- Database Initialization
- Initialize a Database Using JPA
- Initialize a Database Using Hibernate
- Initialize a Database
- Initialize a Spring Batch Database
- Use a Higher-level Database Migration Tool
- Execute Flyway Database Migrations on Startup
- Execute Liquibase Database Migrations on Startup
- Messaging
- Disable Transacted JMS Session
- Batch Applications
- Execute Spring Batch Jobs on Startup
- Actuator
- Change the HTTP Port or Address of the Actuator Endpoints
- Customize the ‘whitelabel’ Error Page
- Sanitize sensible values
- Security
- Switch off the Spring Boot Security Configuration
- Change the UserDetailsService and Add User Accounts
- Enable HTTPS When Running behind a Proxy Server
- Hot Swapping
- Reload Static Content
- Reload Templates without Restarting the Container
- Thymeleaf Templates
- FreeMarker Templates
- Groovy Templates
- Fast Application Restarts
- Reload Java Classes without Restarting the Container
- Build
- Generate Build Information
- Generate Git Information
- Customize Dependency Versions
- Create an Executable JAR with Maven
- Use a Spring Boot Application as a Dependency
- Extract Specific Libraries When an Executable Jar Runs
- Create a Non-executable JAR with Exclusions
- Remote Debug a Spring Boot Application Started with Maven
- Build an Executable Archive from Ant without Using spring-boot-antlib
- Traditional Deployment
- Create a Deployable War File
- Convert an Existing Application to Spring Boot
- Deploying a WAR to WebLogic
- Use Jedis Instead of Lettuce
- Spring Boot Application
- Appendices
- Appendix A: Common application properties
- Core properties
- Cache properties
- Mail properties
- JSON properties
- Data properties
- Transaction properties
- Data migration properties
- Integration properties
- Web properties
- Templating properties
- Server properties
- Security properties
- RSocket properties
- Actuator properties
- Devtools properties
- Testing properties
- Appendix B: Configuration Metadata
- Metadata Format
- Group Attributes
- Property Attributes
- Hint Attributes
- Repeated Metadata Items
- Providing Manual Hints
- Value Hint
- Value Providers
- Generating Your Own Metadata by Using the Annotation Processor
- Nested Properties
- Adding Additional Metadata
- Metadata Format
- Appendix C: Auto-configuration classes
- From the “spring-boot-autoconfigure” module
- From the “spring-boot-actuator-autoconfigure” module
- Appendix D: Test Auto-configuration Annotations
- Appendix E: The Executable Jar Format
- Nested JARs
- The Executable Jar File Structure
- The Executable War File Structure
- Spring Boot’s “JarFile” Class
- Compatibility with the Standard Java “JarFile”
- Launching Executable Jars
- Launcher Manifest
- Exploded Archives
- PropertiesLauncher Features
- Executable Jar Restrictions
- Alternative Single Jar Solutions
- Nested JARs
- Appendix F: Dependency versions
- Appendix A: Common application properties