Spring Boot

Table of Contents

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