logo资料库

SpringBoot官方英文参考资料.pdf

第1页 / 共345页
第2页 / 共345页
第3页 / 共345页
第4页 / 共345页
第5页 / 共345页
第6页 / 共345页
第7页 / 共345页
第8页 / 共345页
资料共345页,剩余部分请下载后查看
Spring Boot Reference Guide
Table of Contents
Part I. 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
Part II. Getting started
8. Introducing Spring Boot
9. System Requirements
9.1 Servlet containers
10. Installing Spring Boot
10.1 Installation instructions for the Java developer
Maven installation
Gradle installation
10.2 Installing the Spring Boot CLI
Manual installation
Installation with SDKMAN!
OSX Homebrew installation
MacPorts installation
Command-line completion
Quick start Spring CLI example
10.3 Upgrading from an earlier version of Spring Boot
11. Developing your first Spring Boot application
11.1 Creating the POM
11.2 Adding classpath dependencies
11.3 Writing the code
The @RestController and @RequestMapping annotations
The @EnableAutoConfiguration annotation
The “main” method
11.4 Running the example
11.5 Creating an executable jar
12. What to read next
Part III. Using Spring Boot
13. Build systems
13.1 Dependency management
13.2 Maven
Inheriting the starter parent
Using Spring Boot without the parent POM
Changing the Java version
Using the Spring Boot Maven plugin
13.3 Gradle
13.4 Ant
13.5 Starters
14. Structuring your code
14.1 Using the “default” package
14.2 Locating the main application class
15. Configuration classes
15.1 Importing additional configuration classes
15.2 Importing XML configuration
16. Auto-configuration
16.1 Gradually replacing auto-configuration
16.2 Disabling specific auto-configuration
17. Spring Beans and dependency injection
18. Using the @SpringBootApplication annotation
19. Running your application
19.1 Running from an IDE
19.2 Running as a packaged application
19.3 Using the Maven plugin
19.4 Using the Gradle plugin
19.5 Hot swapping
20. Developer tools
20.1 Property defaults
20.2 Automatic restart
Excluding resources
Watching additional paths
Disabling restart
Using a trigger file
Customizing the restart classloader
Known limitations
20.3 LiveReload
20.4 Global settings
20.5 Remote applications
Running the remote client application
Remote update
Remote debug tunnel
21. Packaging your application for production
22. What to read next
Part IV. Spring Boot features
23. SpringApplication
23.1 Customizing the Banner
23.2 Customizing SpringApplication
23.3 Fluent builder API
23.4 Application events and listeners
23.5 Web environment
23.6 Accessing application arguments
23.7 Using the ApplicationRunner or CommandLineRunner
23.8 Application exit
23.9 Admin features
24. Externalized Configuration
24.1 Configuring random values
24.2 Accessing command line properties
24.3 Application property files
24.4 Profile-specific properties
24.5 Placeholders in properties
24.6 Using YAML instead of Properties
Loading YAML
Exposing YAML as properties in the Spring Environment
Multi-profile YAML documents
YAML shortcomings
Merging YAML lists
24.7 Type-safe Configuration Properties
Third-party configuration
Relaxed binding
Properties conversion
@ConfigurationProperties Validation
@ConfigurationProperties vs. @Value
25. Profiles
25.1 Adding active profiles
25.2 Programmatically setting profiles
25.3 Profile-specific configuration files
26. Logging
26.1 Log format
26.2 Console output
Color-coded output
26.3 File output
26.4 Log Levels
26.5 Custom log configuration
26.6 Logback extensions
Profile-specific configuration
Environment properties
27. Developing web applications
27.1 The ‘Spring Web MVC framework’
Spring MVC auto-configuration
HttpMessageConverters
Custom JSON Serializers and Deserializers
MessageCodesResolver
Static Content
ConfigurableWebBindingInitializer
Template engines
Error Handling
Custom error pages
Mapping error pages outside of Spring MVC
Error Handling on WebSphere Application Server
Spring HATEOAS
CORS support
27.2 JAX-RS and Jersey
27.3 Embedded servlet container support
Servlets, Filters, and listeners
Registering Servlets, Filters, and listeners as Spring beans
Servlet Context Initialization
Scanning for Servlets, Filters, and listeners
The EmbeddedWebApplicationContext
Customizing embedded servlet containers
Programmatic customization
Customizing ConfigurableEmbeddedServletContainer directly
JSP limitations
28. Security
28.1 OAuth2
Authorization Server
Resource Server
28.2 Token Type in User Info
28.3 Customizing the User Info RestTemplate
Client
Single Sign On
28.4 Actuator Security
29. Working with SQL databases
29.1 Configure a DataSource
Embedded Database Support
Connection to a production database
Connection to a JNDI DataSource
29.2 Using JdbcTemplate
29.3 JPA and ‘Spring Data’
Entity Classes
Spring Data JPA Repositories
Creating and dropping JPA databases
29.4 Using H2’s web console
Changing the H2 console’s path
Securing the H2 console
30. Using jOOQ
30.1 Code Generation
30.2 Using DSLContext
30.3 Customizing jOOQ
31. Working with NoSQL technologies
31.1 Redis
Connecting to Redis
31.2 MongoDB
Connecting to a MongoDB database
MongoTemplate
Spring Data MongoDB repositories
Embedded Mongo
31.3 Neo4j
Connecting to a Neo4j database
Using the embedded mode
Neo4jSession
Spring Data Neo4j repositories
Repository example
31.4 Gemfire
31.5 Solr
Connecting to Solr
Spring Data Solr repositories
31.6 Elasticsearch
Connecting to Elasticsearch using Jest
Connecting to Elasticsearch using Spring Data
Spring Data Elasticsearch repositories
31.7 Cassandra
Connecting to Cassandra
Spring Data Cassandra repositories
31.8 Couchbase
Connecting to Couchbase
Spring Data Couchbase repositories
32. Caching
32.1 Supported cache providers
Generic
JCache
EhCache 2.x
Hazelcast
Infinispan
Couchbase
Redis
Caffeine
Guava
Simple
None
33. Messaging
33.1 JMS
ActiveMQ support
Artemis support
HornetQ support
Using a JNDI ConnectionFactory
Sending a message
Receiving a message
33.2 AMQP
RabbitMQ support
Sending a message
Receiving a message
34. Calling REST services
34.1 RestTemplate customization
35. Sending email
36. Distributed Transactions with JTA
36.1 Using an Atomikos transaction manager
36.2 Using a Bitronix transaction manager
36.3 Using a Narayana transaction manager
36.4 Using a Java EE managed transaction manager
36.5 Mixing XA and non-XA JMS connections
36.6 Supporting an alternative embedded transaction manager
37. Hazelcast
38. Spring Integration
39. Spring Session
40. Monitoring and management over JMX
41. Testing
41.1 Test scope dependencies
41.2 Testing Spring applications
41.3 Testing Spring Boot applications
Detecting test configuration
Excluding test configuration
Working with random ports
Mocking and spying beans
Auto-configured tests
Auto-configured JSON tests
Auto-configured Spring MVC tests
Auto-configured Data JPA tests
Auto-configured REST clients
Auto-configured Spring REST Docs tests
Using Spock to test Spring Boot applications
41.4 Test utilities
ConfigFileApplicationContextInitializer
EnvironmentTestUtils
OutputCapture
TestRestTemplate
42. WebSockets
43. Web Services
44. Creating your own auto-configuration
44.1 Understanding auto-configured beans
44.2 Locating auto-configuration candidates
44.3 Condition annotations
Class conditions
Bean conditions
Property conditions
Resource conditions
Web application conditions
SpEL expression conditions
44.4 Creating your own starter
Naming
Autoconfigure module
Starter module
45. What to read next
Part V. Spring Boot Actuator: Production-ready features
46. Enabling production-ready features
47. Endpoints
47.1 Customizing endpoints
47.2 Hypermedia for actuator MVC endpoints
47.3 CORS support
47.4 Adding custom endpoints
47.5 Health information
47.6 Security with HealthIndicators
Auto-configured HealthIndicators
Writing custom HealthIndicators
47.7 Application information
Auto-configured InfoContributors
Custom application info information
Git commit information
Build information
Writing custom InfoContributors
48. Monitoring and management over HTTP
48.1 Securing sensitive endpoints
48.2 Customizing the management endpoint paths
48.3 Customizing the management server port
48.4 Configuring management-specific SSL
48.5 Customizing the management server address
48.6 Disabling HTTP endpoints
48.7 HTTP health endpoint access restrictions
49. Monitoring and management over JMX
49.1 Customizing MBean names
49.2 Disabling JMX endpoints
49.3 Using Jolokia for JMX over HTTP
Customizing Jolokia
Disabling Jolokia
50. Monitoring and management using a remote shell
50.1 Connecting to the remote shell
Remote shell credentials
50.2 Extending the remote shell
Remote shell commands
Remote shell plugins
51. Metrics
51.1 System metrics
51.2 DataSource metrics
51.3 Cache metrics
51.4 Tomcat session metrics
51.5 Recording your own metrics
51.6 Adding your own public metrics
51.7 Special features with Java 8
51.8 Metric writers, exporters and aggregation
Example: Export to Redis
Example: Export to Open TSDB
Example: Export to Statsd
Example: Export to JMX
51.9 Aggregating metrics from multiple sources
51.10 Dropwizard Metrics
51.11 Message channel integration
52. Auditing
53. Tracing
53.1 Custom tracing
54. Process monitoring
54.1 Extend configuration
54.2 Programmatically
55. What to read next
Part VI. Deploying Spring Boot applications
56. Deploying to the cloud
56.1 Cloud Foundry
Binding to services
56.2 Heroku
56.3 OpenShift
56.4 Boxfuse and Amazon Web Services
56.5 Google App Engine
57. Installing Spring Boot applications
57.1 Unix/Linux services
Installation as an init.d service (System V)
Securing an init.d service
Installation as a systemd service
Customizing the startup script
Customizing script when it’s written
Customizing script when it runs
58. Microsoft Windows services
59. What to read next
Part VII. Spring Boot CLI
60. Installing the CLI
61. Using the CLI
61.1 Running applications using the CLI
Deduced “grab” dependencies
Deduced “grab” coordinates
Default import statements
Automatic main method
Custom dependency management
61.2 Testing your code
61.3 Applications with multiple source files
61.4 Packaging your application
61.5 Initialize a new project
61.6 Using the embedded shell
61.7 Adding extensions to the CLI
62. Developing application with the Groovy beans DSL
63. Configuring the CLI with settings.xml
64. What to read next
Part VIII. Build tool plugins
65. Spring Boot Maven plugin
65.1 Including the plugin
65.2 Packaging executable jar and war files
66. Spring Boot Gradle plugin
66.1 Including the plugin
66.2 Gradle dependency management
66.3 Packaging executable jar and war files
66.4 Running a project in-place
66.5 Spring Boot plugin configuration
66.6 Repackage configuration
66.7 Repackage with custom Gradle configuration
Configuration options
Available layouts
66.8 Understanding how the Gradle plugin works
66.9 Publishing artifacts to a Maven repository using Gradle
Configuring Gradle to produce a pom that inherits dependency management
Configuring Gradle to produce a pom that imports dependency management
67. Spring Boot AntLib module
67.1 Spring Boot Ant tasks
spring-boot:exejar
Examples
67.2 spring-boot:findmainclass
Examples
68. Supporting other build systems
68.1 Repackaging archives
68.2 Nested libraries
68.3 Finding a main class
68.4 Example repackage implementation
69. What to read next
Part IX. ‘How-to’ guides
70. Spring Boot application
70.1 Troubleshoot auto-configuration
70.2 Customize the Environment or ApplicationContext before it starts
70.3 Build an ApplicationContext hierarchy (adding a parent or root context)
70.4 Create a non-web application
71. Properties & configuration
71.1 Automatically expand properties at build time
Automatic property expansion using Maven
Automatic property expansion using Gradle
71.2 Externalize the configuration of SpringApplication
71.3 Change the location of external properties of an application
71.4 Use ‘short’ command line arguments
71.5 Use YAML for external properties
71.6 Set the active Spring profiles
71.7 Change configuration depending on the environment
71.8 Discover built-in options for external properties
72. Embedded servlet containers
72.1 Add a Servlet, Filter or Listener to an application
Add a Servlet, Filter or Listener using a Spring bean
Disable registration of a Servlet or Filter
Add Servlets, Filters, and Listeners using classpath scanning
72.2 Change the HTTP port
72.3 Use a random unassigned HTTP port
72.4 Discover the HTTP port at runtime
72.5 Configure SSL
72.6 Configure Access Logging
72.7 Use behind a front-end proxy server
Customize Tomcat’s proxy configuration
72.8 Configure Tomcat
72.9 Enable Multiple Connectors with Tomcat
72.10 Use Jetty instead of Tomcat
72.11 Configure Jetty
72.12 Use Undertow instead of Tomcat
72.13 Configure Undertow
72.14 Enable Multiple Listeners with Undertow
72.15 Use Tomcat 7.x or 8.0
Use Tomcat 7.x or 8.0 with Maven
Use Tomcat 7.x or 8.0 with Gradle
72.16 Use Jetty 9.2
Use Jetty 9.2 with Maven
Use Jetty 9.2 with Gradle
72.17 Use Jetty 8
Use Jetty 8 with Maven
Use Jetty 8 with Gradle
72.18 Create WebSocket endpoints using @ServerEndpoint
72.19 Enable HTTP response compression
73. Spring MVC
73.1 Write a JSON REST service
73.2 Write an XML REST service
73.3 Customize the Jackson ObjectMapper
73.4 Customize the @ResponseBody rendering
73.5 Handling Multipart File Uploads
73.6 Switch off the Spring MVC DispatcherServlet
73.7 Switch off the Default MVC configuration
73.8 Customize ViewResolvers
73.9 Velocity
73.10 Use Thymeleaf 3
74. HTTP clients
74.1 Configure RestTemplate to use a proxy
75. Logging
75.1 Configure Logback for logging
Configure logback for file only output
75.2 Configure Log4j for logging
Use YAML or JSON to configure Log4j 2
76. Data Access
76.1 Configure a DataSource
76.2 Configure Two DataSources
76.3 Use Spring Data repositories
76.4 Separate @Entity definitions from Spring configuration
76.5 Configure JPA properties
76.6 Use a custom EntityManagerFactory
76.7 Use Two EntityManagers
76.8 Use a traditional persistence.xml
76.9 Use Spring Data JPA and Mongo repositories
76.10 Expose Spring Data repositories as REST endpoint
76.11 Configure a component that is used by JPA
77. Database initialization
77.1 Initialize a database using JPA
77.2 Initialize a database using Hibernate
77.3 Initialize a database using Spring JDBC
77.4 Initialize a Spring Batch database
77.5 Use a higher-level database migration tool
Execute Flyway database migrations on startup
Execute Liquibase database migrations on startup
78. Batch applications
78.1 Execute Spring Batch jobs on startup
79. Actuator
79.1 Change the HTTP port or address of the actuator endpoints
79.2 Customize the ‘whitelabel’ error page
79.3 Actuator and Jersey
80. Security
80.1 Switch off the Spring Boot security configuration
80.2 Change the AuthenticationManager and add user accounts
80.3 Enable HTTPS when running behind a proxy server
81. Hot swapping
81.1 Reload static content
81.2 Reload templates without restarting the container
Thymeleaf templates
FreeMarker templates
Groovy templates
Velocity templates
81.3 Fast application restarts
81.4 Reload Java classes without restarting the container
Configuring Spring Loaded for use with Maven
Configuring Spring Loaded for use with Gradle and IntelliJ IDEA
82. Build
82.1 Generate build information
82.2 Generate git information
82.3 Customize dependency versions
82.4 Create an executable JAR with Maven
82.5 Create an additional executable JAR
82.6 Extract specific libraries when an executable jar runs
82.7 Create a non-executable JAR with exclusions
82.8 Remote debug a Spring Boot application started with Maven
82.9 Remote debug a Spring Boot application started with Gradle
82.10 Build an executable archive from Ant without using spring-boot-antlib
82.11 How to use Java 6
Embedded servlet container compatibility
JTA API compatibility
83. Traditional deployment
83.1 Create a deployable war file
83.2 Create a deployable war file for older servlet containers
83.3 Convert an existing application to Spring Boot
83.4 Deploying a WAR to WebLogic
83.5 Deploying a WAR in an Old (Servlet 2.5) Container
Part X. Appendices
Appendix A. Common application properties
Appendix B. Configuration meta-data
B.1 Meta-data format
Group Attributes
Property Attributes
Hint Attributes
Repeated meta-data items
B.2 Providing manual hints
Value hint
Value provider
Any
Class reference
Handle As
Logger name
Spring bean reference
Spring profile name
B.3 Generating your own meta-data using the annotation processor
Nested properties
Adding additional meta-data
Appendix C. Auto-configuration classes
C.1 From the “spring-boot-autoconfigure” module
C.2 From the “spring-boot-actuator” module
Appendix D. Test auto-configuration annotations
Appendix E. The executable jar format
E.1 Nested JARs
The executable jar file structure
The executable war file structure
E.2 Spring Boot’s “JarFile” class
Compatibility with the standard Java “JarFile”
E.3 Launching executable jars
Launcher manifest
Exploded archives
E.4 PropertiesLauncher Features
E.5 Executable jar restrictions
Zip entry compression
System ClassLoader
E.6 Alternative single jar solutions
Appendix F. Dependency versions
Spring Boot Reference Guide 1.4.0.BUILD-SNAPSHOT Phillip Webb , Dave Syer , Josh Long , Stéphane Nicoll , Rob Winch , Andy Wilkinson , Marcel Overdijk , Christian Dupuis , Sébastien Deleuze Copyright © 2013-2016 Copies of this document may be made for your own use and for distribution to others, provided that you do not charge any fee for such copies and further provided that each copy contains this Copyright Notice, whether distributed in print or electronically.
Spring Boot Reference Guide Table of Contents I. Spring Boot Documentation ...................................................................................................... 1 1. About the documentation ................................................................................................ 2 2. Getting help .................................................................................................................... 3 3. First steps ...................................................................................................................... 4 4. Working with Spring Boot ................................................................................................ 5 5. Learning about Spring Boot features ................................................................................ 6 6. Moving to production ....................................................................................................... 7 7. Advanced topics ............................................................................................................. 8 II. Getting started ........................................................................................................................ 9 8. Introducing Spring Boot ................................................................................................. 10 9. System Requirements ................................................................................................... 11 9.1. Servlet containers ............................................................................................... 11 10. Installing Spring Boot .................................................................................................. 12 10.1. Installation instructions for the Java developer ................................................... 12 Maven installation ............................................................................................. 12 Gradle installation ............................................................................................. 13 10.2. Installing the Spring Boot CLI ........................................................................... 14 Manual installation ............................................................................................ 14 Installation with SDKMAN! ................................................................................. 15 OSX Homebrew installation ............................................................................... 15 MacPorts installation ......................................................................................... 15 Command-line completion ................................................................................. 16 Quick start Spring CLI example ......................................................................... 16 10.3. Upgrading from an earlier version of Spring Boot ............................................... 16 11. Developing your first Spring Boot application ................................................................ 17 11.1. Creating the POM ............................................................................................ 17 11.2. Adding classpath dependencies ........................................................................ 18 11.3. Writing the code ............................................................................................... 19 The @RestController and @RequestMapping annotations .................................. 19 The @EnableAutoConfiguration annotation ........................................................ 19 The “main” method ........................................................................................... 20 11.4. Running the example ........................................................................................ 20 11.5. Creating an executable jar ................................................................................ 20 12. What to read next ....................................................................................................... 22 III. Using Spring Boot ................................................................................................................ 23 13. Build systems ............................................................................................................. 24 13.1. Dependency management ................................................................................ 24 13.2. Maven .............................................................................................................. 24 Inheriting the starter parent ............................................................................... 24 Using Spring Boot without the parent POM ........................................................ 25 Changing the Java version ................................................................................ 26 Using the Spring Boot Maven plugin .................................................................. 26 13.3. Gradle .............................................................................................................. 26 13.4. Ant ................................................................................................................... 27 13.5. Starters ............................................................................................................ 28 14. Structuring your code .................................................................................................. 34 14.1. Using the “default” package .............................................................................. 34 1.4.0.BUILD-SNAPSHOT Spring Boot ii
Spring Boot Reference Guide 14.2. Locating the main application class ................................................................... 34 15. Configuration classes .................................................................................................. 36 15.1. Importing additional configuration classes .......................................................... 36 15.2. Importing XML configuration .............................................................................. 36 16. Auto-configuration ....................................................................................................... 37 16.1. Gradually replacing auto-configuration ............................................................... 37 16.2. Disabling specific auto-configuration .................................................................. 37 17. Spring Beans and dependency injection ....................................................................... 38 18. Using the @SpringBootApplication annotation .............................................................. 39 19. Running your application ............................................................................................. 40 19.1. Running from an IDE ........................................................................................ 40 19.2. Running as a packaged application ................................................................... 40 19.3. Using the Maven plugin .................................................................................... 40 19.4. Using the Gradle plugin .................................................................................... 41 19.5. Hot swapping ................................................................................................... 41 20. Developer tools ........................................................................................................... 42 20.1. Property defaults .............................................................................................. 42 20.2. Automatic restart .............................................................................................. 43 Excluding resources .......................................................................................... 44 Watching additional paths .................................................................................. 44 Disabling restart ................................................................................................ 44 Using a trigger file ............................................................................................ 45 Customizing the restart classloader .................................................................... 45 Known limitations .............................................................................................. 45 20.3. LiveReload ....................................................................................................... 46 20.4. Global settings ................................................................................................. 46 20.5. Remote applications ......................................................................................... 46 Running the remote client application ................................................................. 46 Remote update ................................................................................................. 47 Remote debug tunnel ........................................................................................ 48 21. Packaging your application for production ..................................................................... 49 22. What to read next ....................................................................................................... 50 IV. Spring Boot features ............................................................................................................ 51 23. SpringApplication ......................................................................................................... 52 23.1. Customizing the Banner .................................................................................... 52 23.2. Customizing SpringApplication .......................................................................... 53 23.3. Fluent builder API ............................................................................................. 54 23.4. Application events and listeners ........................................................................ 54 23.5. Web environment ............................................................................................. 55 23.6. Accessing application arguments ....................................................................... 55 23.7. Using the ApplicationRunner or CommandLineRunner ........................................ 56 23.8. Application exit ................................................................................................. 56 23.9. Admin features ................................................................................................. 56 24. Externalized Configuration ........................................................................................... 58 24.1. Configuring random values ............................................................................... 59 24.2. Accessing command line properties .................................................................. 59 24.3. Application property files ................................................................................... 59 24.4. Profile-specific properties .................................................................................. 61 24.5. Placeholders in properties ................................................................................. 61 24.6. Using YAML instead of Properties ..................................................................... 61 1.4.0.BUILD-SNAPSHOT Spring Boot iii
Spring Boot Reference Guide Loading YAML .................................................................................................. 62 Exposing YAML as properties in the Spring Environment .................................... 62 Multi-profile YAML documents ........................................................................... 62 YAML shortcomings .......................................................................................... 63 Merging YAML lists ........................................................................................... 63 24.7. Type-safe Configuration Properties .................................................................... 64 Third-party configuration .................................................................................... 66 Relaxed binding ................................................................................................ 66 Properties conversion ........................................................................................ 67 @ConfigurationProperties Validation .................................................................. 67 @ConfigurationProperties vs. @Value ............................................................... 68 25. Profiles ....................................................................................................................... 70 25.1. Adding active profiles ....................................................................................... 70 25.2. Programmatically setting profiles ....................................................................... 70 25.3. Profile-specific configuration files ....................................................................... 71 26. Logging ....................................................................................................................... 72 26.1. Log format ....................................................................................................... 72 26.2. Console output ................................................................................................. 72 Color-coded output ............................................................................................ 73 26.3. File output ........................................................................................................ 74 26.4. Log Levels ....................................................................................................... 74 26.5. Custom log configuration .................................................................................. 75 26.6. Logback extensions .......................................................................................... 76 Profile-specific configuration .............................................................................. 77 Environment properties ...................................................................................... 77 27. Developing web applications ........................................................................................ 78 27.1. The ‘Spring Web MVC framework’ .................................................................... 78 Spring MVC auto-configuration .......................................................................... 78 HttpMessageConverters .................................................................................... 79 Custom JSON Serializers and Deserializers ....................................................... 79 MessageCodesResolver .................................................................................... 80 Static Content ................................................................................................... 80 ConfigurableWebBindingInitializer ...................................................................... 81 Template engines .............................................................................................. 81 Error Handling .................................................................................................. 82 Custom error pages .................................................................................. 83 Mapping error pages outside of Spring MVC .............................................. 83 Error Handling on WebSphere Application Server ....................................... 84 Spring HATEOAS .............................................................................................. 84 CORS support .................................................................................................. 84 27.2. JAX-RS and Jersey .......................................................................................... 85 27.3. Embedded servlet container support .................................................................. 86 Servlets, Filters, and listeners ............................................................................ 86 Registering Servlets, Filters, and listeners as Spring beans ......................... 86 Servlet Context Initialization ............................................................................... 86 Scanning for Servlets, Filters, and listeners ................................................ 87 The EmbeddedWebApplicationContext ............................................................... 87 Customizing embedded servlet containers .......................................................... 87 Programmatic customization ...................................................................... 88 Customizing ConfigurableEmbeddedServletContainer directly ...................... 88 1.4.0.BUILD-SNAPSHOT Spring Boot iv
Spring Boot Reference Guide JSP limitations .................................................................................................. 88 28. Security ...................................................................................................................... 89 28.1. OAuth2 ............................................................................................................ 90 Authorization Server .......................................................................................... 90 Resource Server ............................................................................................... 90 28.2. Token Type in User Info ................................................................................... 91 28.3. Customizing the User Info RestTemplate ........................................................... 91 Client ................................................................................................................ 91 Single Sign On ................................................................................................. 92 28.4. Actuator Security .............................................................................................. 93 29. Working with SQL databases ....................................................................................... 94 29.1. Configure a DataSource ................................................................................... 94 Embedded Database Support ............................................................................ 94 Connection to a production database ................................................................. 95 Connection to a JNDI DataSource ..................................................................... 96 29.2. Using JdbcTemplate ......................................................................................... 96 29.3. JPA and ‘Spring Data’ ...................................................................................... 96 Entity Classes ................................................................................................... 97 Spring Data JPA Repositories ........................................................................... 98 Creating and dropping JPA databases ............................................................... 98 29.4. Using H2’s web console ................................................................................... 99 Changing the H2 console’s path ........................................................................ 99 Securing the H2 console ................................................................................... 99 30. Using jOOQ .............................................................................................................. 100 30.1. Code Generation ............................................................................................ 100 30.2. Using DSLContext .......................................................................................... 100 30.3. Customizing jOOQ .......................................................................................... 101 31. Working with NoSQL technologies ............................................................................. 102 31.1. Redis ............................................................................................................. 102 Connecting to Redis ........................................................................................ 102 31.2. MongoDB ....................................................................................................... 102 Connecting to a MongoDB database ................................................................ 102 MongoTemplate .............................................................................................. 103 Spring Data MongoDB repositories .................................................................. 104 Embedded Mongo ........................................................................................... 104 31.3. Neo4j ............................................................................................................. 104 Connecting to a Neo4j database ...................................................................... 105 Using the embedded mode .............................................................................. 105 Neo4jSession .................................................................................................. 105 Spring Data Neo4j repositories ........................................................................ 105 Repository example ......................................................................................... 106 31.4. Gemfire .......................................................................................................... 106 31.5. Solr ................................................................................................................ 106 Connecting to Solr .......................................................................................... 106 Spring Data Solr repositories ........................................................................... 107 31.6. Elasticsearch .................................................................................................. 107 Connecting to Elasticsearch using Jest ............................................................ 107 Connecting to Elasticsearch using Spring Data ................................................. 107 Spring Data Elasticsearch repositories ............................................................. 108 31.7. Cassandra ...................................................................................................... 108 1.4.0.BUILD-SNAPSHOT Spring Boot v
Spring Boot Reference Guide Connecting to Cassandra ................................................................................ 108 Spring Data Cassandra repositories ................................................................. 109 31.8. Couchbase ..................................................................................................... 109 Connecting to Couchbase ................................................................................ 109 Spring Data Couchbase repositories ................................................................ 109 32. Caching .................................................................................................................... 111 32.1. Supported cache providers ............................................................................. 111 Generic ........................................................................................................... 112 JCache ........................................................................................................... 112 EhCache 2.x ................................................................................................... 113 Hazelcast ........................................................................................................ 113 Infinispan ........................................................................................................ 113 Couchbase ...................................................................................................... 114 Redis .............................................................................................................. 114 Caffeine .......................................................................................................... 114 Guava ............................................................................................................. 115 Simple ............................................................................................................ 115 None ............................................................................................................... 115 33. Messaging ................................................................................................................ 116 33.1. JMS ............................................................................................................... 116 ActiveMQ support ............................................................................................ 116 Artemis support ............................................................................................... 116 HornetQ support .............................................................................................. 117 Using a JNDI ConnectionFactory ..................................................................... 118 Sending a message ........................................................................................ 118 Receiving a message ...................................................................................... 119 33.2. AMQP ............................................................................................................ 120 RabbitMQ support ........................................................................................... 120 Sending a message ........................................................................................ 120 Receiving a message ...................................................................................... 121 34. Calling REST services ............................................................................................... 123 34.1. RestTemplate customization ............................................................................ 123 35. Sending email ........................................................................................................... 125 36. Distributed Transactions with JTA .............................................................................. 126 36.1. Using an Atomikos transaction manager .......................................................... 126 36.2. Using a Bitronix transaction manager .............................................................. 126 36.3. Using a Narayana transaction manager ........................................................... 127 36.4. Using a Java EE managed transaction manager .............................................. 127 36.5. Mixing XA and non-XA JMS connections ......................................................... 127 36.6. Supporting an alternative embedded transaction manager ................................ 128 37. Hazelcast .................................................................................................................. 129 38. Spring Integration ...................................................................................................... 130 39. Spring Session .......................................................................................................... 131 40. Monitoring and management over JMX ...................................................................... 132 41. Testing ...................................................................................................................... 133 41.1. Test scope dependencies ............................................................................... 133 41.2. Testing Spring applications ............................................................................. 133 41.3. Testing Spring Boot applications ..................................................................... 133 Detecting test configuration .............................................................................. 134 Excluding test configuration ............................................................................. 135 1.4.0.BUILD-SNAPSHOT Spring Boot vi
Spring Boot Reference Guide Working with random ports .............................................................................. 135 Mocking and spying beans .............................................................................. 136 Auto-configured tests ....................................................................................... 136 Auto-configured JSON tests ............................................................................. 137 Auto-configured Spring MVC tests ................................................................... 138 Auto-configured Data JPA tests ....................................................................... 139 Auto-configured REST clients .......................................................................... 140 Auto-configured Spring REST Docs tests ......................................................... 141 Using Spock to test Spring Boot applications .................................................... 142 41.4. Test utilities .................................................................................................... 142 ConfigFileApplicationContextInitializer ............................................................... 142 EnvironmentTestUtils ....................................................................................... 142 OutputCapture ................................................................................................. 143 TestRestTemplate ........................................................................................... 143 42. WebSockets .............................................................................................................. 144 43. Web Services ............................................................................................................ 145 44. Creating your own auto-configuration ......................................................................... 146 44.1. Understanding auto-configured beans .............................................................. 146 44.2. Locating auto-configuration candidates ............................................................ 146 44.3. Condition annotations ..................................................................................... 146 Class conditions .............................................................................................. 147 Bean conditions .............................................................................................. 147 Property conditions .......................................................................................... 147 Resource conditions ........................................................................................ 147 Web application conditions .............................................................................. 147 SpEL expression conditions ............................................................................. 148 44.4. Creating your own starter ................................................................................ 148 Naming ........................................................................................................... 148 Autoconfigure module ...................................................................................... 148 Starter module ................................................................................................ 149 45. What to read next ..................................................................................................... 150 V. Spring Boot Actuator: Production-ready features .................................................................. 151 46. Enabling production-ready features ............................................................................ 152 47. Endpoints .................................................................................................................. 153 47.1. Customizing endpoints .................................................................................... 154 47.2. Hypermedia for actuator MVC endpoints .......................................................... 155 47.3. CORS support ................................................................................................ 155 47.4. Adding custom endpoints ................................................................................ 155 47.5. Health information .......................................................................................... 156 47.6. Security with HealthIndicators ......................................................................... 156 Auto-configured HealthIndicators ...................................................................... 156 Writing custom HealthIndicators ....................................................................... 157 47.7. Application information .................................................................................... 157 Auto-configured InfoContributors ...................................................................... 157 Custom application info information .................................................................. 158 Git commit information ..................................................................................... 158 Build information ............................................................................................. 158 Writing custom InfoContributors ....................................................................... 159 48. Monitoring and management over HTTP .................................................................... 160 48.1. Securing sensitive endpoints ........................................................................... 160 1.4.0.BUILD-SNAPSHOT Spring Boot vii
Spring Boot Reference Guide 48.2. Customizing the management endpoint paths .................................................. 160 48.3. Customizing the management server port ........................................................ 161 48.4. Configuring management-specific SSL ............................................................. 161 48.5. Customizing the management server address .................................................. 161 48.6. Disabling HTTP endpoints ............................................................................... 162 48.7. HTTP health endpoint access restrictions ........................................................ 162 49. Monitoring and management over JMX ...................................................................... 163 49.1. Customizing MBean names ............................................................................. 163 49.2. Disabling JMX endpoints ................................................................................. 163 49.3. Using Jolokia for JMX over HTTP ................................................................... 163 Customizing Jolokia ......................................................................................... 163 Disabling Jolokia ............................................................................................. 163 50. Monitoring and management using a remote shell ....................................................... 165 50.1. Connecting to the remote shell ........................................................................ 165 Remote shell credentials ................................................................................. 165 50.2. Extending the remote shell .............................................................................. 166 Remote shell commands ................................................................................. 166 Remote shell plugins ....................................................................................... 166 51. Metrics ...................................................................................................................... 168 51.1. System metrics ............................................................................................... 168 51.2. DataSource metrics ........................................................................................ 169 51.3. Cache metrics ................................................................................................ 169 51.4. Tomcat session metrics .................................................................................. 170 51.5. Recording your own metrics ............................................................................ 170 51.6. Adding your own public metrics ....................................................................... 170 51.7. Special features with Java 8 ........................................................................... 171 51.8. Metric writers, exporters and aggregation ......................................................... 171 Example: Export to Redis ................................................................................ 171 Example: Export to Open TSDB ...................................................................... 172 Example: Export to Statsd ............................................................................... 173 Example: Export to JMX .................................................................................. 173 51.9. Aggregating metrics from multiple sources ....................................................... 173 51.10. Dropwizard Metrics ....................................................................................... 174 51.11. Message channel integration ......................................................................... 174 52. Auditing ..................................................................................................................... 175 53. Tracing ..................................................................................................................... 176 53.1. Custom tracing ............................................................................................... 176 54. Process monitoring .................................................................................................... 177 54.1. Extend configuration ....................................................................................... 177 54.2. Programmatically ............................................................................................ 177 55. What to read next ..................................................................................................... 178 VI. Deploying Spring Boot applications ..................................................................................... 179 56. Deploying to the cloud ............................................................................................... 180 56.1. Cloud Foundry ................................................................................................ 180 Binding to services .......................................................................................... 181 56.2. Heroku ........................................................................................................... 181 56.3. OpenShift ....................................................................................................... 183 56.4. Boxfuse and Amazon Web Services ................................................................ 183 56.5. Google App Engine ........................................................................................ 184 57. Installing Spring Boot applications .............................................................................. 185 1.4.0.BUILD-SNAPSHOT Spring Boot viii
分享到:
收藏