├── X. Appendices
├── README.md
├── B.2.2. Adding additional meta-data.md
├── D.5. Executable jar restrictions.md
├── C.2. From the “spring-boot-actuator” module.md
├── D.5.1. Zip entry compression.md
├── E. Dependency versions.md
├── B.1.3. Repeated meta-data items.md
├── D.2.1. Compatibility with the standard Java “JarFile”.md
├── D. The executable jar format.md
├── D.5.2. System ClassLoader.md
├── C. Auto-configuration classes.md
├── D.3.2. Exploded archives.md
├── B. Configuration meta-data.md
├── D.1. Nested JARs.md
├── D.6. Alternative single jar solutions.md
├── B.2.1. Nested properties.md
├── D.1.1. The executable jar file structure.md
├── D.3. Launching executable jars.md
├── D.3.1. Launcher manifest.md
├── B.1.1. Group Attributes.md
├── D.1.2. The executable war file structure.md
├── D.2. Spring Boot’s “JarFile” class.md
└── B.1.2. Property Attributes.md
├── IX. ‘How-to’ guides
├── 80. Build.md
├── 78. Security.md
├── 72. HTTP clients.md
├── 74. Data Access.md
├── 79. Hot swapping.md
├── 71. Spring MVC.md
├── 77. Actuator.md
├── 76. Batch applications.md
├── 81. Traditional deployment.md
├── 69. Properties & configuration.md
├── 68. Spring Boot application.md
├── 70. Embedded servlet containers.md
├── 75. Database initialization.md
├── 80.11 How to use Java 6.md
├── 80.11.2 Jackson.md
├── 70.3 Use a random unassigned HTTP port.md
├── 69.1. Automatically expand properties at build time.md
├── 70.17 Use Jetty 9.2.md
├── 71.7 Switch off the Default MVC configuration.md
├── 70.16 Use Tomcat 7.x or 8.0.md
├── 70.18 Use Jetty 8.md
├── 75.5 Use a higher level database migration tool.md
├── 74.6 Use a custom EntityManagerFactory.md
├── 79.2. Reload templates without restarting the container.md
├── 70.1 Add a Servlet, Filter or ServletContextListener to an application.md
├── 75.1 Initialize a database using JPA.md
├── 81.2 Create a deployable war file for older servlet containers.md
├── 75.4 Initialize a Spring Batch database.md
├── 70.1.2 Add Servlets, Filters, and Listeners using classpath scanning.md
├── 71.6 Switch off the Spring MVC DispatcherServlet.md
├── 68.4 Build an ApplicationContext hierarchy (adding a parent or root context).md
├── 80.11.1 Embedded servlet container compatibility.md
├── 80.11.3 JTA API compatibility.md
├── 79.2.4 Velocity templates.md
├── 79.3 Fast application restarts.md
├── 80.8 Remote debug a Spring Boot application started with Maven.md
├── 79.2.1 Thymeleaf templates.md
├── 79.2.2 FreeMarker templates.md
├── 79.2.3 Groovy templates.md
├── 79.4 Reload Java classes without restarting the container.md
├── README.md
├── 77.3 Actuator and Jersey.md
├── 74.4 Separate @Entity definitions from Spring configuration.md
├── 70.16.2 Use Tomcat 7.x or 8.0 with Gradle.md
├── 70.12 Configure Jetty.md
├── 79.1 Reload static content.md
├── 70.7 Use behind a front-end proxy server.md
├── 74.8 Use a traditional persistence.xml.md
├── 68.5 Create a non-web application.md
├── 70.8 Configure Tomcat.md
├── 73.2.1 Use YAML or JSON to configure Log4j 2.md
├── 70.20 Enable HTTP response compression.md
├── 70.17.2 Use Jetty 9.2 with Gradle.md
├── 70.14 Configure Undertow.md
├── 70.19 Create WebSocket endpoints using @ServerEndpoint.md
├── 69.1.2. Automatic property expansion using Gradle.md
├── 75.2 Initialize a database using Hibernate.md
├── 74.9 Use Spring Data JPA and Mongo repositories.md
├── 71.1 Write a JSON REST service.md
├── 74.10 Expose Spring Data repositories as REST endpoint.md
├── 80.9 Remote debug a Spring Boot application started with Gradle.md
├── 78.1 Switch off the Spring Boot security configuration.md
├── 69.8 Discover built-in options for external properties.md
├── 74.2 Configure Two DataSources.md
├── 70.18.2 Use Jetty 8 with Gradle.md
├── 70.2 Change the HTTP port.md
├── 77.1 Change the HTTP port or address of the actuator endpoints.md
├── 71.9 Velocity.md
├── 68.1 Create your own FailureAnalyzer.md
├── 75.5.2 Execute Liquibase database migrations on startup.md
├── 69.4 Use ‘short’ command line arguments.md
├── 79.4.1 Configuring Spring Loaded for use with Maven.md
├── 80.2 Generate git information.md
├── 69.6 Set the active Spring profiles.md
├── 71.5 Handling Multipart File Uploads.md
├── 70.15 Enable Multiple Listeners with Undertow.md
├── 70.6 Configure Access Logging.md
├── 70.16.1 Use Tomcat 7.x or 8.0 with Maven.md
├── 74.3 Use Spring Data repositories.md
├── 73.1.1 Configure logback for file only output.md
├── 70.7.1 Customize Tomcat’s proxy configuration.md
├── 71.10 Use Thymeleaf 3.md
├── 78.3 Enable HTTPS when running behind a proxy server.md
├── 69.7 Change configuration depending on the environment.md
├── 77.2 Customize the ‘whitelabel’ error page.md
├── 70.4 Discover the HTTP port at runtime.md
└── 75.3 Initialize a database using Spring JDBC.md
├── IV. Spring Boot features
├── 40.4 Test utilities.md
├── 31.1.10 Simple.md
├── 24.6.4. YAML shortcomings.md
├── 29.4.1 Changing the H2 console’s path.md
├── 31.1.1 Generic.md
├── 43.3.4 Resource conditions.md
├── 29.1. Configure a DataSource.md
├── 30.3.3 Neo4jSession.md
├── 27.3 Embedded servlet container support.md
├── 31.1.11 None.md
├── 29. Working with SQL databases.md
├── 32.2 AMQP.md
├── 43.4.3 Starter module.md
├── 25.2. Programmatically setting profiles.md
├── 28.2 Token Type in User Info.md
├── 30.2. MongoDB.md
├── 29.5 Using jOOQ.md
├── 26.6 Logback extensions.md
├── 43.3.6 SpEL expression conditions.md
├── 24.6.2. Exposing YAML as properties in the Spring Environment.md
├── 30.3 Neo4j.md
├── 43.3.3 Property conditions.md
├── 29.4.2 Securing the H2 console.md
├── 42. Web Services.md
├── 28.1 OAuth2.md
├── 31.1.7 Redis.md
├── 27.1.6 ConfigurableWebBindingInitializer.md
├── 43.3.1 Class conditions.md
├── 43.4.2 Autoconfigure module.md
├── 31.1.5 Infinispan.md
├── 43.3 Condition annotations.md
├── 43.4 Creating your own starter.md
├── 31.1.3 EhCache 2.x.md
├── 43.3.5 Web Application Conditions.md
├── 30.5 Solr.md
├── 40. Testing.md
├── 30.7.2 Spring Data Cassandra repositories.md
├── 40.4.2 EnvironmentTestUtils.md
├── 30.8 Couchbase.md
├── 32. Messaging.md
├── 30.7 Cassandra.md
├── 25.3. Profile specific configuration files.md
├── 30.1. Redis.md
├── 27.1.4 MessageCodesResolver.md
├── 23.9 Application exit.md
├── 24.2. Accessing command line properties.md
├── 30.6 Elasticsearch.md
├── 41. WebSockets.md
├── 24.6. Using YAML instead of Properties.md
├── 27.1.3 Custom JSON Serializers and Deserializers.md
├── 32.1.4 Using a JNDI ConnectionFactory.md
├── README.md
├── 27. Developing web applications.md
├── 32.1. JMS.md
├── 30.3.2 Using the embedded mode.md
├── 30.5.2 Spring Data Solr repositories.md
├── 24.7.3 Properties conversion.md
├── 30.6.3 Spring Data Elasticsearch repositories.md
├── 24.5. Placeholders in properties.md
├── 30.6.1 Connecting to Elasticsearch using Jest.md
├── 27.1.9 Spring HATEOAS.md
├── 39. Monitoring and management over JMX.md
├── 29.1.3. Connection to a JNDI DataSource.md
├── 30.5.1 Connecting to Solr.md
├── 24.7.1. Third-party configuration.md
├── 35. Distributed Transactions with JTA.md
├── 35.4 Using a Java EE managed transaction manager.md
├── 40.3.5 Auto-configured tests.md
├── 23.10 Admin features.md
├── 28.4 Actuator Security.md
├── 31.1.4 Hazelcast.md
├── 23.6. Web environment.md
├── 24.1. Configuring random values.md
├── 44. What to read next.md
├── 26.2. Console output.md
├── 30.3.4 Spring Data Neo4j repositories.md
├── 30.4 Gemfire.md
├── 37. Spring Integration.md
├── 43.1 Understanding auto-configured beans.md
├── 27.3.3 The EmbeddedWebApplicationContext.md
├── 43.3.2 Bean conditions.md
├── 27.3.5 JSP limitations.md
├── 30.3.5 Repository example.md
├── 40.2 Testing Spring applications.md
├── 29.4 Using H2’s web console.md
├── 43. Creating your own auto-configuration.md
├── 30.2.4 Embedded Mongo.md
├── 29.5.3 Customizing jOOQ.md
├── 32.2.1 RabbitMQ support.md
├── 26.3. File output.md
├── 25. Profiles.md
├── 28.1.1 Authorization Server.md
├── 34. Sending email.md
├── 26. Logging.md
├── 40.3.2 Excluding test configuration.md
├── 27.3.1 Servlets, Filters, and listeners.md
├── 29.2. Using JdbcTemplate.md
├── 40.4.1 ConfigFileApplicationContextInitializer.md
├── 30.1.1. Connecting to Redis.md
├── 31.1.9 Guava.md
├── 36. Hazelcast.md
├── 32.1.1 ActiveMQ support.md
├── 40.4.3 OutputCapture.md
├── 40.3.1 Detecting test configuration.md
├── 23.4. Fluent builder API.md
├── 27.3.2 Servlet Context Initialization.md
├── 26.4. Log Levels.md
├── 26.6.1 Profile-specific configuration.md
├── 29.3.3. Creating and dropping JPA databases.md
├── 30.7.1 Connecting to Cassandra.md
├── 43.4.1 Naming.md
├── 38. Spring Session.md
├── 35.3 Using a Narayana transaction manager.md
├── 35.2 Using a Bitronix transaction manager.md
├── 24.4. Profile-specific properties.md
├── 31.1.8 Caffeine.md
├── 30. Working with NoSQL technologies.md
├── 28.3 Customizing the User Info RestTemplate.md
├── 32.1.5 Sending a message.md
├── 23.3. Customizing SpringApplication.md
├── 40.1 Test scope dependencies.md
├── 26.6.2 Environment properties.md
├── 30.3.1 Connecting to a Neo4j database.md
├── 30.2.3. Spring Data MongoDB repositories.md
├── 30.8.2 Spring Data Couchbase repositories.md
├── 35.1 Using an Atomikos transaction manager.md
├── 23.8 Using the ApplicationRunner or CommandLineRunner.md
├── 30.2.2. MongoTemplate.md
├── 26.2.1 Color-coded output.md
├── 30.8.1 Connecting to Couchbase.md
├── 29.5.2 Using DSLContext.md
└── 23.7 Accessing application arguments.md
├── V. Spring Boot Actuator
├── 49.2 Extending the remote shell.md
├── 47.6 Disabling HTTP endpoints.md
├── 53.2 Programmatically.md
├── 48.2 Disabling JMX endpoints.md
├── 48. Monitoring and management over JMX.md
├── 47. Monitoring and management over HTTP.md
├── 50.4 Tomcat session metrics.md
├── 49.2.2 Remote shell plugins.md
├── 50.6 Adding your own public metrics.md
├── 48.3.2 Disabling Jolokia.md
├── 48.3.1 Customizing Jolokia.md
├── 50.11 Message channel integration.md
├── 46.7 Application information.md
├── 53. Process monitoring.md
├── 46.6 Security with HealthIndicators.md
├── 53.1 Extend configuration.md
├── 46.7.4 Build information.md
├── 47.5 Customizing the management server address.md
├── 48.3 Using Jolokia for JMX over HTTP.md
├── README.md
├── 52.1 Custom tracing.md
├── 48.1 Customizing MBean names.md
├── 50.8.4 Export to JMX.md
├── 51. Auditing.md
├── 50.7 Special features with Java 8.md
├── 54. What to read next.md
├── 46.4 Adding custom endpoints.md
├── 50.1 System metrics.md
├── 49. Monitoring and management using a remote shell.md
├── 47.3 Customizing the management server port.md
├── 49.1.1 Remote shell credentials.md
├── 46.5 Health information.md
├── 46.7.3 Git commit information.md
├── 50.3 Cache metrics.md
├── 50.10 Dropwizard Metrics.md
├── 47.1 Securing sensitive endpoints.md
├── 50.2 DataSource metrics.md
├── 46.7.2 Custom application info information.md
├── 46.3 CORS support.md
├── 50.8.3 Export to Statsd.md
├── 47.7 HTTP Health endpoint access restrictions.md
├── 46.2 Hypermedia for actuator MVC endpoints.md
├── 46.1 Customizing endpoints.md
├── 47.4 Configuring management-specific SSL.md
├── 47.2 Customizing the management endpoint paths.md
├── 45. Enabling production-ready features.md
└── 50.8.2 Export to Open TSDB.md
├── I. Spring Boot Documentation
├── README.md
├── 1. About the documentation.md
├── 3. First steps.md
├── 2. Getting help.md
├── 6. Moving to production.md
└── 7. Advanced topics.md
├── III. Using Spring Boot
├── 14. Structuring your code.md
├── 15.2. Importing XML configuration.md
├── 13. Build systems.md
├── 15.1. Importing additional configuration classes.md
├── 20.5.2 Remote update.md
├── 19. Running your application.md
├── README.md
├── 13.2.3. Changing the Java version.md
├── 20.2.6 Known limitations.md
├── 20.2.2 Watching additional paths.md
├── 16.1. Gradually replacing auto-configuration.md
├── 15. Configuration classes.md
├── 21. Packaging your application for production.md
├── 19.3. Using the Maven plugin.md
├── 14.1. Using the “default” package.md
├── 20.4 Global settings.md
├── 19.4. Using the Gradle plugin.md
├── 22. What to read next.md
├── 20.3 LiveReload.md
├── 16. Auto-configuration.md
├── 20.5 Remote applications.md
├── 19.2. Running as a packaged application.md
├── 20.2.3 Disabling restart.md
├── 20.2.4 Using a trigger file.md
├── 20.2.1 Excluding resources.md
├── 19.5. Hot swapping.md
├── 20.1 Property defaults.md
├── 19.1. Running from an IDE.md
├── 13.2.4. Using the Spring Boot Maven plugin.md
├── 16.2. Disabling specific auto-configuration.md
├── 13.1. Dependency management.md
├── 20.5.3 Remote debug tunnel.md
└── 13.2.1. Inheriting the starter parent.md
├── VIII. Build tool plugins
├── 65.1. Spring Boot Ant tasks.md
├── 64. Spring Boot Gradle plugin.md
├── 66.2.Nested libraries.md
├── 66.3. Finding a main class.md
├── 66.1. Repackaging archives.md
├── 64.5 Spring Boot plugin configuration.md
├── README.md
├── 64.9 Publishing artifacts to a Maven repository using Gradle.md
├── 65.2. spring-boot:findmainclass.md
├── 65.2.1. Examples.md
├── 66. Supporting other build systems.md
├── 67. What to read next.md
├── 63. Spring Boot Maven plugin.md
├── 64.4 Running a project in-place.md
├── 66.4. Example repackage implementation.md
├── 64.1 Including the plugin.md
├── 65.1.1. spring-boot:exejar.md
├── 65.1.2. Examples.md
├── 64.7.1 Configuration options.md
├── 65. Spring Boot AntLib module.md
├── 64.9.1 Configuring Gradle to produce a pom that inherits dependency management.md
└── 64.7.2 Available layouts.md
├── VI. Deploying Spring Boot applications
├── 56.1 Unix&Linux services.md
├── README.md
├── 55.5 Google App Engine.md
├── 56.2 Microsoft Windows services.md
├── 55. Deploying to the cloud.md
└── 57. What to read next.md
├── VII. Spring Boot CLI
├── README.md
├── 59.1.4 Automatic main method.md
├── 58. Installing the CLI.md
├── 59.1.3 Default import statements.md
├── 59.3 Applications with multiple source files.md
├── 59.1.2 Deduced “grab” coordinates.md
├── 61. Configuring the CLI with settings.xml.md
├── 62. What to read next.md
├── 59.6 Using the embedded shell.md
├── 59.4 Packaging your application.md
├── 59.2 Testing your code.md
├── 59.7 Adding extensions to the CLI.md
├── 59.1. Running applications using the CLI.md
└── 60. Developing application with the Groovy beans DSL.md
├── II. Getting started
├── README.md
├── 10.2.4. MacPorts installation.md
├── 10.2. Installing the Spring Boot CLI.md
├── 11.3.3. The “main” method.md
├── 10.1. Installation instructions for the Java developer.md
├── 10.2.3. OSX Homebrew installation.md
├── 9. System Requirements.md
├── 10.3. Upgrading from an earlier version of Spring Boot.md
├── 9.1. Servlet containers.md
├── 11.3.2. The @EnableAutoConfiguration annotation.md
├── 10. Installing Spring Boot.md
├── 8. Introducing Spring Boot.md
├── 11.3.1. The @RestController and @RequestMapping annotations.md
├── 10.2.6. Quick start Spring CLI example.md
├── 10.2.5. Command-line completion.md
├── 12. What to read next.md
├── 11.3. Writing the code.md
├── 11.4. Running the example.md
└── 10.2.1. Manual installation.md
├── .gitignore
└── README.md
/X. Appendices/README.md:
--------------------------------------------------------------------------------
1 | ### X.附录
2 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/80. Build.md:
--------------------------------------------------------------------------------
1 | ### 80. 构建
2 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/78. Security.md:
--------------------------------------------------------------------------------
1 | ### 78. 安全
2 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/72. HTTP clients.md:
--------------------------------------------------------------------------------
1 | ###72. HTTP客户端
2 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/74. Data Access.md:
--------------------------------------------------------------------------------
1 | ### 74. 数据访问
2 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/79. Hot swapping.md:
--------------------------------------------------------------------------------
1 | ### 79. 热交换
2 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/71. Spring MVC.md:
--------------------------------------------------------------------------------
1 | ### 71. Spring MVC
2 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/77. Actuator.md:
--------------------------------------------------------------------------------
1 | ### 77. 执行器(Actuator)
2 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/76. Batch applications.md:
--------------------------------------------------------------------------------
1 | ### 76. 批处理应用
2 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/81. Traditional deployment.md:
--------------------------------------------------------------------------------
1 | ### 81. 传统部署
2 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/69. Properties & configuration.md:
--------------------------------------------------------------------------------
1 | ### 69. 属性&配置
2 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/68. Spring Boot application.md:
--------------------------------------------------------------------------------
1 | ### 68. Spring Boot应用
2 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/70. Embedded servlet containers.md:
--------------------------------------------------------------------------------
1 | ### 70. 内嵌servlet容器
2 |
--------------------------------------------------------------------------------
/X. Appendices/B.2.2. Adding additional meta-data.md:
--------------------------------------------------------------------------------
1 | ### 附录 B.2.2. 添加其他的元数据
2 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/40.4 Test utilities.md:
--------------------------------------------------------------------------------
1 | ### 40.4 测试工具类
2 | 一些测试工具类也打包进了`spring-boot`,在测试时使用它们会有很大帮助。
3 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/49.2 Extending the remote shell.md:
--------------------------------------------------------------------------------
1 | ### 49.2 扩展远程shell
2 |
3 | 有很多有趣的方式可以用来扩展远程shell。
4 |
--------------------------------------------------------------------------------
/I. Spring Boot Documentation/README.md:
--------------------------------------------------------------------------------
1 | ### Spring Boot文档
2 |
3 | 本节对Spring Boot参考文档做了一个简单概述。你可以参考本节,从头到尾依次阅读该文档,也可以跳过不感兴趣的章节。
4 |
--------------------------------------------------------------------------------
/III. Using Spring Boot/14. Structuring your code.md:
--------------------------------------------------------------------------------
1 | ### 14. 组织你的代码
2 |
3 | Spring Boot不要求使用任何特殊的代码结构,不过,遵循以下的一些最佳实践还是挺有帮助的。
4 |
--------------------------------------------------------------------------------
/VIII. Build tool plugins/65.1. Spring Boot Ant tasks.md:
--------------------------------------------------------------------------------
1 | ###65.1. Spring Boot Ant任务
2 | 一旦声明`spring-boot-antlib`命名空间,以下任务就可用了。
3 |
--------------------------------------------------------------------------------
/X. Appendices/D.5. Executable jar restrictions.md:
--------------------------------------------------------------------------------
1 | ### 附录D.5. 可执行jar的限制
2 |
3 | 当使用Spring Boot Loader打包的应用时有一些你需要考虑的限制。
4 |
5 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/75. Database initialization.md:
--------------------------------------------------------------------------------
1 | ### 75. 数据库初始化
2 |
3 | 一个数据库可以使用不同的方式进行初始化,这取决于你的技术栈。或者你可以手动完成该任务,只要数据库是单独的过程。
4 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/80.11 How to use Java 6.md:
--------------------------------------------------------------------------------
1 | ### 80.11 如何使用Java6
2 |
3 | 如果想在Java6环境中使用Spring Boot,你需要改变一些配置,具体的改变取决于你应用的功能。
4 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/80.11.2 Jackson.md:
--------------------------------------------------------------------------------
1 | ###80.11.2 Jackson
2 |
3 | Jackson 2.7及以后版本需要Java 7,如果想要在Java 6环境使用Jackson,你需要降级使用Jackson 2.6。
4 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/31.1.10 Simple.md:
--------------------------------------------------------------------------------
1 | ###31.1.10 Simple
2 | 如果以上选项都没有采用,一个使用`ConcurrentHashMap`作为缓存存储的简单实现将被配置,这是应用没有添加缓存library的默认设置。
3 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/47.6 Disabling HTTP endpoints.md:
--------------------------------------------------------------------------------
1 | ### 47.6 禁用HTTP端点
2 |
3 | 如果不想通过HTTP暴露端点,你可以将管理端口设置为-1:
4 | `management.port=-1`
5 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/24.6.4. YAML shortcomings.md:
--------------------------------------------------------------------------------
1 | ### 24.6.4. YAML缺点
2 |
3 | YAML文件不能通过`@PropertySource`注解加载,如果需要使用该方式,那就必须使用properties文件。
4 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/70.3 Use a random unassigned HTTP port.md:
--------------------------------------------------------------------------------
1 | ### 70.3 使用随机未分配的HTTP端口
2 |
3 | 想扫描获取一个未使用的端口(使用操作系统本地端口以防冲突)可以设置`server.port=0`。
4 |
--------------------------------------------------------------------------------
/VI. Deploying Spring Boot applications/56.1 Unix&Linux services.md:
--------------------------------------------------------------------------------
1 | ### 56.1 Unix/Linux服务
2 | 你可以使用`init.d`或`systemd`启动Spring Boot应用,就像其他Unix/Linux服务那样。
3 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/29.4.1 Changing the H2 console’s path.md:
--------------------------------------------------------------------------------
1 | ### 29.4.1 改变H2控制台路径
2 | H2控制台路径默认为`/h2-console`,你可以通过设置`spring.h2.console.path`属性自定义该路径。
3 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/69.1. Automatically expand properties at build time.md:
--------------------------------------------------------------------------------
1 | ###69.1. 运行时暴露属性
2 |
3 | 相对于在项目构建配置中硬编码某些配置,你可以使用已存在的构建配置自动暴露它们,Maven和Gradle都支持。
4 |
--------------------------------------------------------------------------------
/X. Appendices/C.2. From the “spring-boot-actuator” module.md:
--------------------------------------------------------------------------------
1 | ### 附录C.2 来自`spring-boot-actuator`模块
2 |
3 | 下列的自动配置类来自于`spring-boot-actuator`模块:
4 |
5 |
6 |
--------------------------------------------------------------------------------
/III. Using Spring Boot/15.2. Importing XML configuration.md:
--------------------------------------------------------------------------------
1 | ### 15.2. 导入XML配置
2 |
3 | 如果必须使用XML配置,建议你仍旧从一个`@Configuration`类开始,然后使用`@ImportResource`注解加载XML配置文件。
4 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/31.1.1 Generic.md:
--------------------------------------------------------------------------------
1 | ###31.1.1 Generic
2 | 如果上下文定义至少一个`org.springframework.cache.Cache` bean,一个配置好的`CacheManager`包装着它们,那么将使用通用(Generic)缓存。
3 |
--------------------------------------------------------------------------------
/III. Using Spring Boot/13. Build systems.md:
--------------------------------------------------------------------------------
1 | ### 13. 构建系统
2 |
3 | 强烈建议你选择一个支持依赖管理,能消费发布到"Maven中央仓库"的artifacts的构建系统,比如Maven或Gradle。使用其他构建系统也是可以的,比如Ant,但它们可能得不到很好的支持。
4 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/43.3.4 Resource conditions.md:
--------------------------------------------------------------------------------
1 | ###43.3.4 Resource条件
2 | `@ConditionalOnResource`注解只在特定资源出现时才会包含配置,可以使用常见的Spring约定命名资源,例如`file:/home/user/test.dat`。
3 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/70.17 Use Jetty 9.2.md:
--------------------------------------------------------------------------------
1 | ### 70.17 使用Jetty9.2
2 |
3 | Spring Boot可以使用Jetty9.2,但默认使用的是Jetty9.3。如果不能使用Jetty9.3(例如,因为你使用的是Java7),你需要改变classpath去引用Jetty9.2。
4 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/29.1. Configure a DataSource.md:
--------------------------------------------------------------------------------
1 | ### 29.1. 配置DataSource
2 |
3 | Java的`javax.sql.DataSource`接口提供了一个标准的使用数据库连接的方法。通常,DataSource使用`URL`和相应的凭证去初始化数据库连接。
4 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/71.7 Switch off the Default MVC configuration.md:
--------------------------------------------------------------------------------
1 | ### 71.7 关闭默认的MVC配置
2 |
3 | 完全控制MVC配置的最简单方式是提供你自己的被`@EnableWebMvc`注解的`@Configuration`,这样所有的MVC配置都逃不出你的掌心。
4 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/53.2 Programmatically.md:
--------------------------------------------------------------------------------
1 |
2 | ### 53.2 以编程方式
3 | 你也可以通过调用`SpringApplication.addListeners(…)`方法并传递相应的`Writer`对象来激活一个监听器,该方法允许你通过`Writer`构造器自定义文件名和路径。
4 |
--------------------------------------------------------------------------------
/VI. Deploying Spring Boot applications/README.md:
--------------------------------------------------------------------------------
1 | ### 部署Spring Boot应用
2 | Spring Boot灵活的打包选项为部署应用提供多种选择,你可以轻易的将Spring Boot应用部署到各种云平台,容器镜像(比如Docker)或虚拟/真实机器。
3 |
4 | 本章节覆盖一些比较常见的部署场景。
5 |
--------------------------------------------------------------------------------
/VII. Spring Boot CLI/README.md:
--------------------------------------------------------------------------------
1 | ### Spring Boot CLI
2 | Spring Boot CLI是一个命令行工具,如果想使用Spring进行快速开发可以使用它。它允许你运行Groovy脚本,这意味着你可以使用熟悉的类Java语法,并且没有那么多的模板代码。你可以通过Spring Boot CLI启动新项目,或为它编写命令。
3 |
--------------------------------------------------------------------------------
/X. Appendices/D.5.1. Zip entry compression.md:
--------------------------------------------------------------------------------
1 | ### 附录D.5.1 Zip实体压缩
2 |
3 | 对于一个嵌套jar的ZipEntry必须使用`ZipEntry.STORED`方法保存。这是需要的,这样我们可以直接查找嵌套jar中的个别内容。嵌套jar的内容本身可以仍旧被压缩,正如外部jar的其他任何实体。
4 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/48.2 Disabling JMX endpoints.md:
--------------------------------------------------------------------------------
1 | ### 48.2 禁用JMX端点
2 | 如果不想通过JMX暴露端点,你可以将`endpoints.jmx.enabled`属性设置为`false`:
3 | ```java
4 | endpoints.jmx.enabled=false
5 | ```
6 |
--------------------------------------------------------------------------------
/II. Getting started/README.md:
--------------------------------------------------------------------------------
1 | ### 入门指南
2 |
3 | 如果你想从大体上了解Spring Boot或Spring,本章节正是你所需要的!本节中,我们会回答基本的"what?","how?"和"why?"等问题,并通过一些安装指南简单介绍下Spring Boot。然后我们会构建第一个Spring Boot应用,并讨论一些需要遵循的核心原则。
4 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/70.16 Use Tomcat 7.x or 8.0.md:
--------------------------------------------------------------------------------
1 | ### 70.16 使用Tomcat 7.x或8.0
2 |
3 | Spring Boot可以使用Tomcat7&8.0,但默认使用的是Tomcat8.5。如果不能使用Tomcat8.5(例如,因为你使用的是Java1.6),你需要改变classpath去引用一个不同版本。
4 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/70.18 Use Jetty 8.md:
--------------------------------------------------------------------------------
1 | ###70.18 使用Jetty 8
2 |
3 | Spring Boot支持Jetty 8,但默认使用的是Jetty 9.3。如果不能使用Jetty 9.3(比如因为你使用的是Java 1.6),你需要改变classpath去引用Jetty 8,还需要排除Jetty的WebSocket相关依赖。
4 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/48. Monitoring and management over JMX.md:
--------------------------------------------------------------------------------
1 | ### 48. 基于JMX的监控和管理
2 |
3 | Java管理扩展(JMX)提供了一种标准的监控和管理应用的机制。默认情况下,Spring Boot在`org.springframework.boot`域下将管理端点暴露为JMX MBeans。
4 |
--------------------------------------------------------------------------------
/X. Appendices/E. Dependency versions.md:
--------------------------------------------------------------------------------
1 | ### 附录E. 依赖版本
2 |
3 | 下面的表格提供了详尽的依赖版本信息,这些版本由Spring Boot自身的CLI,Maven的依赖管理(dependency management)和Gradle插件提供。当你声明一个对以下artifacts的依赖而没有声明版本时,将使用下面表格中列出的版本。
4 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/30.3.3 Neo4jSession.md:
--------------------------------------------------------------------------------
1 | ### 30.3.3 Neo4jSession
2 | Neo4jSession默认的生命周期是应用程序范围,如果运行的是web应用,你可以很轻松的改变它的scope:
3 | ```properties
4 | spring.data.neo4j.session.scope=session
5 | ```
6 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/47. Monitoring and management over HTTP.md:
--------------------------------------------------------------------------------
1 | ### 47. 基于HTTP的监控和管理
2 |
3 | 如果你正在开发一个Spring MVC应用,Spring Boot执行器自动将所有启用的端点通过HTTP暴露出去。默认约定使用端点的`id`作为URL路径,例如,`health`暴露为`/health`。
4 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/27.3 Embedded servlet container support.md:
--------------------------------------------------------------------------------
1 | ### 27.3 内嵌servlet容器支持
2 |
3 | Spring Boot支持内嵌的Tomcat, Jetty和Undertow服务器,多数开发者只需要使用合适的'Starter'来获取一个完全配置好的实例即可,内嵌服务器默认监听8080端口的HTTP请求。
4 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/75.5 Use a higher level database migration tool.md:
--------------------------------------------------------------------------------
1 | ### 75.5 使用高级数据迁移工具
2 |
3 | Spring Boot支持两种高级数据迁移工具[Flyway](http://flywaydb.org/)(基于SQL)和[Liquibase](http://www.liquibase.org/)(XML)。
4 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/50.4 Tomcat session metrics.md:
--------------------------------------------------------------------------------
1 | ### 50.4 Tomcat session指标
2 | 如果你使用Tomcat作为内嵌的servlet容器,Spring Boot将自动暴露session指标,
3 | `httpsessions.active`和`httpsessions.max`分别提供活动的和最大的session数量。
4 |
--------------------------------------------------------------------------------
/VII. Spring Boot CLI/59.1.4 Automatic main method.md:
--------------------------------------------------------------------------------
1 | ###59.1.4 自动创建main方法
2 |
3 | 跟等效的Java应用不同,你不需要在Groovy脚本中添加一个`public static void main(String[] args)`方法。Spring Boot会使用你编译后的代码自动创建一个`SpringApplication`。
4 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/31.1.11 None.md:
--------------------------------------------------------------------------------
1 | ###31.1.11 None
2 | 如果配置类中出现`@EnableCaching`,一个合适的缓存配置也同样被期待。如果在某些环境需要禁用全部缓存,强制将缓存类型设为`none`将会使用一个no-op实现(没有任何实现的实现):
3 | ```properties
4 | spring.cache.type=none
5 | ```
6 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/49.2.2 Remote shell plugins.md:
--------------------------------------------------------------------------------
1 | ### 49.2.2 远程shell插件
2 | 除了创建新命令,你也可以扩展CRaSH shell的其他特性,所有继承`org.crsh.plugin.CRaSHPlugin`的Spring Beans将自动注册到shell,具体查看[CRaSH参考文档](http://www.crashub.org/)。
3 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/50.6 Adding your own public metrics.md:
--------------------------------------------------------------------------------
1 | ### 50.6 添加自己的公共指标
2 | 只要注册其他的`PublicMetrics`实现beans,你就可以添加其他的度量指标,比如计算metrics端点每次调用的次数。默认情况下,端点会聚合所有这样的beans,通过定义自己的`MetricsEndpoint`可以轻易改变这种情况。
3 |
--------------------------------------------------------------------------------
/VIII. Build tool plugins/64. Spring Boot Gradle plugin.md:
--------------------------------------------------------------------------------
1 | ### 64. Spring Boot Gradle插件
2 |
3 | Spring Boot Gradle插件为Gradle提供Spring Boot支持,它允许你打包可执行jar或war存档,运行Spring Boot应用,使用`spring-boot-dependencies`提供的依赖管理。
4 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/29. Working with SQL databases.md:
--------------------------------------------------------------------------------
1 | ### 29. 使用SQL数据库
2 | Spring框架为使用SQL数据库提供了广泛支持,从使用`JdbcTemplate`直接访问JDBC到完全的‘对象关系映射’技术,比如Hibernate。Spring Data提供了更高级的功能,直接从接口创建`Repository`实现,并根据约定从方法名生成查询。
3 |
--------------------------------------------------------------------------------
/III. Using Spring Boot/15.1. Importing additional configuration classes.md:
--------------------------------------------------------------------------------
1 | ### 15.1. 导入其他配置类
2 |
3 | 你不需要将所有的`@Configuration`放进一个单独的类,`@Import`注解可以用来导入其他配置类。另外,你也可以使用`@ComponentScan`注解自动收集所有Spring组件,包括`@Configuration`类。
4 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/32.2 AMQP.md:
--------------------------------------------------------------------------------
1 | ###32.2 AMQP
2 | 高级消息队列协议(AMQP)是一个用于消息中间件的,平台无关的,线路级(wire-level)协议。Spring AMQP项目使用Spring的核心概念开发基于AMQP的消息解决方案,Spring Boot为通过RabbitMQ使用AMQP提供了一些便利,包括`spring-boot-starter-amqp`‘Starter’。
3 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/48.3.2 Disabling Jolokia.md:
--------------------------------------------------------------------------------
1 | ### 48.3.2 禁用Jolokia
2 | 如果正在使用Jolokia,又不想让Spring Boot配置它,你只需要简单的将`endpoints.jolokia.enabled`属性设置为`false`:
3 | ```java
4 | endpoints.jolokia.enabled=false
5 | ```
6 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/43.4.3 Starter module.md:
--------------------------------------------------------------------------------
1 | ###43.4.3 Starter模块
2 | starter模块实际是一个空jar,它的目的是提供使用该library所需的必要依赖。不要对添加你的starter的项目做任何假设,如果你正在自动配置的library需要其他starters,一定要提到它。提供一个合适的默认依赖集可能比较困难,特别是存在大量可选依赖时,你应该避免引入任何非必需的依赖。
3 |
--------------------------------------------------------------------------------
/II. Getting started/10.2.4. MacPorts installation.md:
--------------------------------------------------------------------------------
1 | ### 10.2.4. 使用MacPorts进行安装
2 |
3 | 如果你的环境是Mac,并使用[MacPorts](http://www.macports.org/),想要安装Spring Boot CLI只需以下操作:
4 | ```shell
5 | $ sudo port install spring-boot-cli
6 | ```
7 |
--------------------------------------------------------------------------------
/III. Using Spring Boot/20.5.2 Remote update.md:
--------------------------------------------------------------------------------
1 | ###20.5.2 远程更新
2 | 远程客户端将监听应用的classpath变化,任何更新的资源都会发布到远程应用,并触发重启,这在你使用云服务迭代某个特性时非常有用。通常远程更新和重启比完整rebuild和deploy快多了。
3 |
4 | **注** 文件只有在远程客户端运行时才监控。如果你在启动远程客户端之前改变一个文件,它是不会被发布到远程server的。
5 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/25.2. Programmatically setting profiles.md:
--------------------------------------------------------------------------------
1 | ### 25.2.以编程方式设置profiles
2 |
3 | 在应用运行前,你可以通过调用`SpringApplication.setAdditionalProfiles(…)`方法,以编程的方式设置激活的配置,也可以使用Spring的`ConfigurableEnvironment`接口激活配置(profiles)。
4 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/28.2 Token Type in User Info.md:
--------------------------------------------------------------------------------
1 | ###28.2 User Info中的Token类型
2 |
3 | Google和其他一些第三方身份(identity)提供商对发送给user info端点的请求头中设置的token类型名有严格要求。默认的`Bearer`满足大多数提供商要求,如果需要你可以设置`security.oauth2.resource.token-type`来改变它。
4 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/30.2. MongoDB.md:
--------------------------------------------------------------------------------
1 | ### 30.2. MongoDB
2 |
3 | [MongoDB](http://www.mongodb.com/)是一个开源的NoSQL文档数据库,它使用类JSON格式的模式(schema)替换了传统的基于表的关系数据。Spring Boot为使用MongoDB提供了很多便利,包括`spring-boot-starter-data-mongodb`'Starter'。
4 |
--------------------------------------------------------------------------------
/X. Appendices/B.1.3. Repeated meta-data items.md:
--------------------------------------------------------------------------------
1 | ### 附录B.1.3. 可重复的元数据节点
2 |
3 | 在同一个元数据文件中出现多次相同名称的"property"和"group"对象是可以接受的。例如,Spring Boot将`spring.datasource`属性绑定到Hikari,Tomcat和DBCP类,并且每个都潜在的提供了重复的属性名。这些元数据的消费者需要确保他们支持这样的场景。
4 |
--------------------------------------------------------------------------------
/X. Appendices/D.2.1. Compatibility with the standard Java “JarFile”.md:
--------------------------------------------------------------------------------
1 | ### 附录D.2.1 对标准Java "JarFile"的兼容性
2 |
3 | Spring Boot Loader努力保持对已有代码和库的兼容。`org.springframework.boot.loader.jar.JarFile`继承自`java.util.jar.JarFile`,可以作为降级替换。
4 |
--------------------------------------------------------------------------------
/III. Using Spring Boot/19. Running your application.md:
--------------------------------------------------------------------------------
1 | ### 19. 运行应用程序
2 |
3 | 将应用打包成jar,并使用内嵌HTTP服务器的一个最大好处是,你可以像其他方式那样运行你的应用程序。调试Spring Boot应用也很简单,你都不需要任何特殊IDE插件或扩展!
4 |
5 | **注**:本章节只覆盖基于jar的打包,如果选择将应用打包成war文件,你最好参考相关的服务器和IDE文档。
6 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/29.5 Using jOOQ.md:
--------------------------------------------------------------------------------
1 | ### 29.5 使用jOOQ
2 | Java面向对象查询([jOOQ](http://www.jooq.org/))是[Data Geekery](http://www.datageekery.com/)的一个明星产品,可以从数据库生成Java代码,让你通过它的流式API构建类型安全的SQL查询。不管是商业版,还是开源版本都能跟Spring Boot一块使用。
3 |
4 |
5 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/74.6 Use a custom EntityManagerFactory.md:
--------------------------------------------------------------------------------
1 | ### 74.6 使用自定义EntityManagerFactory
2 |
3 | 为了完全控制`EntityManagerFactory`的配置,你需要添加一个名为`entityManagerFactory`的`@Bean`,Spring Boot自动配置会根据是否存在该类型的bean来关闭它的实体管理器(entity manager)。
4 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/26.6 Logback extensions.md:
--------------------------------------------------------------------------------
1 | ### 26.6 Logback扩展
2 | Spring Boot包含很多有用的Logback扩展,你可以在`logback-spring.xml`配置文件中使用它们。
3 |
4 | **注** 你不能在标准的`logback.xml`配置文件中使用扩展,因为它加载的太早了,不过可以使用`logback-spring.xml`,或指定`logging.config`属性。
5 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/43.3.6 SpEL expression conditions.md:
--------------------------------------------------------------------------------
1 | ###43.3.6 SpEL表达式条件
2 | `@ConditionalOnExpression`注解可以根据[SpEL表达式](http://docs.spring.io/spring/docs/4.3.3.RELEASE/spring-framework-reference/htmlsingle/#expressions)结果来决定是否包含配置。
3 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/48.3.1 Customizing Jolokia.md:
--------------------------------------------------------------------------------
1 | ### 48.3.1 自定义Jolokia
2 | Jolokia有很多配置,通常使用servlet参数进行设置,跟Spring Boot一块使用时可以在`application.properties`中添加`jolokia.config.`前缀的属性进行配置:
3 | ```java
4 | jolokia.config.debug=true
5 | ```
6 |
--------------------------------------------------------------------------------
/X. Appendices/D. The executable jar format.md:
--------------------------------------------------------------------------------
1 | ### 附录D. 可执行jar格式
2 |
3 | `spring-boot-loader`模块允许Spring Boot对可执行jar和war文件的支持。如果你正在使用Maven或Gradle插件,可执行jar会被自动产生,通常你不需要了解它是如何工作的。
4 |
5 | 如果你需要从一个不同的构建系统创建可执行jars,或你只是对底层技术好奇,本章节将提供一些背景资料。
6 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/24.6.2. Exposing YAML as properties in the Spring Environment.md:
--------------------------------------------------------------------------------
1 | ### 24.6.2. 在Spring环境中使用YAML暴露属性
2 |
3 | `YamlPropertySourceLoader`类能够将YAML作为`PropertySource`导出到Sprig `Environment`,这允许你使用常用的`@Value`注解配合占位符语法访问YAML属性。
4 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/50.11 Message channel integration.md:
--------------------------------------------------------------------------------
1 | ### 50.11 消息渠道集成
2 | 如果存在名为`metricsChannel`的`MessageChannel` bean,Spring Boot将创建一个`MetricWriter`将指标写入该渠道(channel)。writer自动挂钩一个exporter,所以全部指标值都会出现在渠道上, 订阅者就可以进行其他分析或动作(提供渠道和订阅者取决于你)。
3 |
--------------------------------------------------------------------------------
/X. Appendices/D.5.2. System ClassLoader.md:
--------------------------------------------------------------------------------
1 | ### 附录D.5.2. 系统ClassLoader
2 |
3 | 启动的应用在加载类时应该使用`Thread.getContextClassLoader()`(多数库和框架都默认这样做)。尝试通过`ClassLoader.getSystemClassLoader()`加载嵌套的类将失败。请注意`java.util.Logging`总是使用系统类加载器,由于这个原因你需要考虑一个不同的日志实现。
4 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/30.3 Neo4j.md:
--------------------------------------------------------------------------------
1 | ### 30.3 Neo4j
2 | [Neo4j](http://neo4j.com/)是一个开源的NoSQL图数据库,它使用图(graph)相关的概念来描述数据模型,把数据保存为图中的节点以及节点之间的关系。相比传统rdbms(关系管理系统)的方式,Neo4j更适合大数据关系分析。Spring Boot为使用Neo4j提供很多便利,包括`spring-boot-starter-data-neo4j`‘Starter’。
3 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/43.3.3 Property conditions.md:
--------------------------------------------------------------------------------
1 | ###43.3.3 Property条件
2 | `@ConditionalOnProperty`注解可以根据一个Spring `Environment`属性来决定是否包含配置,使用`prefix`和`name`属性指定要检查的配置。默认情况下,任何存在的只要不是`false`的属性都会匹配,你也可以使用`havingValue`和`matchIfMissing`属性创建更高级的检测。
3 |
--------------------------------------------------------------------------------
/VIII. Build tool plugins/66.2.Nested libraries.md:
--------------------------------------------------------------------------------
1 | ### 66.2. 内嵌库
2 |
3 | 当重新打包一个存档时,你可以使用`org.springframework.boot.loader.tools.Libraries`接口来包含对依赖文件的引用。在这里我们不提供任何该`Libraries`接口的具体实现,因为它们通常跟具体的构建系统相关。
4 |
5 | 如果存档已经包含libraries,你可以使用`Libraries.NONE`。
6 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/29.4.2 Securing the H2 console.md:
--------------------------------------------------------------------------------
1 | ### 29.4.2 保护H2控制台
2 | 当添加Spring Security依赖,并且启用基本认证时,Spring Boot自动使用基本认证保护H2控制台。以下属性可用于自定义安全配置:
3 |
4 | * `security.user.role`
5 | * `security.basic.authorize-mode`
6 | * `security.basic.enabled`
7 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/42. Web Services.md:
--------------------------------------------------------------------------------
1 | ###42. Web Services
2 | Spring Boot提供Web Services自动配置,你需要的就是定义`Endpoints`。通过添加`spring-boot-starter-webservices`模块可以获取[Spring Web Services特性](http://docs.spring.io/spring-ws/docs/2.3.0.RELEASE/reference/htmlsingle)。
3 |
--------------------------------------------------------------------------------
/VIII. Build tool plugins/66.3. Finding a main class.md:
--------------------------------------------------------------------------------
1 | ### 66.3. 查找main类
2 |
3 | 如果你没有使用`Repackager.setMainClass()`指定一个main类,该repackager将使用[ASM](http://asm.ow2.org/)去读取class文件,然后尝试查找一个合适的,具有`public static void main(String[] args)`方法的类。如果发现多个候选者,将会抛出异常。
4 |
--------------------------------------------------------------------------------
/X. Appendices/C. Auto-configuration classes.md:
--------------------------------------------------------------------------------
1 | ### 附录C. 自动配置类
2 |
3 | 这里有一个Spring Boot提供的所有自动配置类的文档链接和源码列表。也要记着看一下你的应用都开启了哪些自动配置(使用`--debug`或`-Debug`启动应用,或在一个Actuator应用中使用`autoconfig`端点)。
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/X. Appendices/D.3.2. Exploded archives.md:
--------------------------------------------------------------------------------
1 | ### 附录D.3.2. 暴露的存档
2 |
3 | 一些PaaS实现可能选择在运行前先解压存档。例如,Cloud Foundry就是这样操作的。你可以运行一个解压的存档,只需简单的启动合适的启动器:
4 | ```shell
5 | $ unzip -q myapp.jar
6 | $ java org.springframework.boot.loader.JarLaunche
7 | ```
8 |
9 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/28.1 OAuth2.md:
--------------------------------------------------------------------------------
1 | ###28.1 OAuth2
2 | 如果添加了`spring-security-oauth2`依赖,你可以利用自动配置简化认证(Authorization)或资源服务器(Resource Server)的设置,详情参考[Spring Security OAuth 2 Developers Guide](http://projects.spring.io/spring-security-oauth/docs/oauth2.html)。
3 |
4 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/31.1.7 Redis.md:
--------------------------------------------------------------------------------
1 | ###31.1.7 Redis
2 | 如果Redis可用,并配置好了,`RedisCacheManager`将被自动配置,使用`spring.cache.cache-names`可以在启动时创建其他缓存。
3 |
4 | **注** 默认会添加key前缀以防止两个单独的缓存使用相同的key,否则Redis将存在重复的key,有可能返回不可用的值。如果创建自己的`RedisCacheManager`,强烈建议你保留该配置处于启用状态。
5 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/79.2. Reload templates without restarting the container.md:
--------------------------------------------------------------------------------
1 | ###79.2. 在不重启容器的情况下重新加载模板
2 |
3 | Spring Boot支持的大多数模板技术包含一个禁用缓存的配置选项,如果你正在使用`spring-boot-devtools`模块,Spring Boot在开发期间会自动为你[配置那些属性](../III. Using Spring Boot/20.1 Property defaults.md)。
4 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/27.1.6 ConfigurableWebBindingInitializer.md:
--------------------------------------------------------------------------------
1 | ### 27.1.6 ConfigurableWebBindingInitializer
2 | Spring MVC使用`WebBindingInitializer`为每个特殊的请求初始化相应的`WebDataBinder`,如果你创建自己的`ConfigurableWebBindingInitializer @Bean`,Spring Boot会自动配置Spring MVC使用它。
3 |
4 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/43.3.1 Class conditions.md:
--------------------------------------------------------------------------------
1 | ###43.3.1 Class条件
2 | `@ConditionalOnClass`和`@ConditionalOnMissingClass`注解可以根据特定类是否出现来决定配置的包含,由于注解元数据是使用[ASM](http://asm.ow2.org/)来解析的,所以你可以使用`value`属性来引用真正的类,即使该类没有出现在运行应用的classpath下,也可以使用`name`属性如果你倾向于使用字符串作为类名。
3 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/43.4.2 Autoconfigure module.md:
--------------------------------------------------------------------------------
1 | ###43.4.2 自动配置模块
2 | 自动配置模块包含了使用该library需要的任何东西,它可能还包含配置的keys定义(`@ConfigurationProperties`)和用于定义组件如何初始化的回调接口。
3 |
4 | **注** 你需要将对该library的依赖标记为可选的,这样在项目中添加该自动配置模块就更容易了。如果你这样做,该library将不会提供,Spring Boot会回退到默认设置。
5 |
--------------------------------------------------------------------------------
/VI. Deploying Spring Boot applications/55.5 Google App Engine.md:
--------------------------------------------------------------------------------
1 | ###55.5 Google App Engine
2 | Google App Engine关联了Servlet 2.5 API,如果不做一些修改你是不能在其上部署Spring应用的,具体查看本指南的[Servlet 2.5章节](../IX. ‘How-to’ guides/81.5. Deploying a WAR in an Old (Servlet 2.5) Container.md)。
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.class
2 |
3 | # Mobile Tools for Java (J2ME)
4 | .mtj.tmp/
5 |
6 | # Package Files #
7 | *.jar
8 | *.war
9 | *.ear
10 |
11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
12 | hs_err_pid*
13 |
14 | _book
15 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/31.1.5 Infinispan.md:
--------------------------------------------------------------------------------
1 | ###31.1.5 Infinispan
2 | Infinispan没有默认的配置文件位置,所以需要显式指定:
3 | ```properties
4 | spring.cache.infinispan.config=infinispan.xml
5 | ```
6 | 通过设置`spring.cache.cache-names`属性可以让缓存在启动时就被创建,如果定义了`ConfigurationBuilder` bean,它将用来定义该实例。
7 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/43.3 Condition annotations.md:
--------------------------------------------------------------------------------
1 | ###43.3 条件注解
2 | 你几乎总是需要在自己的自动配置类里添加一个或更多的`@Conditional`注解。`@ConditionalOnMissingBean`注解是一个常见的示例,开发者可以用它覆盖自动配置类提供的默认行为。
3 |
4 | Spring Boot包含很多`@Conditional`注解,你可以在自己的代码中通过注解`@Configuration`类或单独的`@Bean`方法来重用它们。
5 |
--------------------------------------------------------------------------------
/X. Appendices/B. Configuration meta-data.md:
--------------------------------------------------------------------------------
1 | ### 附录B. 配置元数据
2 |
3 | Spring Boot jars包含元数据文件,它们提供了所有支持的配置属性详情。这些文件设计用于让IDE开发者能够为使用`application.properties`或`application.yml`文件的用户提供上下文帮助及代码完成功能。
4 |
5 |
6 | 主要的元数据文件是在编译器通过处理所有被`@ConfigurationProperties`注解的节点来自动生成的。
7 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/43.4 Creating your own starter.md:
--------------------------------------------------------------------------------
1 | ###43.4 创建自己的starter
2 | 一个完整的Spring Boot starter可能包含以下组件:
3 |
4 | * `autoconfigure`模块,包含自动配置类的代码。
5 | * `starter`模块,提供自动配置模块及其他有用的依赖,简而言之,添加本starter就能开始使用该library。
6 |
7 | **注** 如果不需要将它们分离开来,你可以将自动配置代码和依赖管理放到一个单一模块中。
8 |
--------------------------------------------------------------------------------
/III. Using Spring Boot/README.md:
--------------------------------------------------------------------------------
1 | ### 使用Spring Boot
2 | 本章节将详细介绍如何使用Spring Boot,不仅覆盖构建系统,自动配置,如何运行应用等主题,还包括一些Spring Boot的最佳实践。尽管Spring Boot本身没有什么特别的(跟其他一样,它只是另一个你可以使用的库),但仍有一些建议,如果遵循的话将会事半功倍。
3 |
4 | 如果你刚接触Spring Boot,那最好先阅读上一章节的[Getting Started](../II. Getting started/README.md)指南。
5 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/31.1.3 EhCache 2.x.md:
--------------------------------------------------------------------------------
1 | ###31.1.3 EhCache 2.x
2 | 如果在classpath下的根目录可以找到一个名为`ehcache.xml`的文件,则缓存将使用EhCache 2.x。如果EhCache 2.x和这样的文件出现,那它们将用于启动缓存管理器,使用以下配置可提供替换的配置文件:
3 | ```properties
4 | spring.cache.ehcache.config=classpath:config/another-config.xml
5 | ```
6 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/43.3.5 Web Application Conditions.md:
--------------------------------------------------------------------------------
1 | ###43.3.5 Web Application条件
2 | `@ConditionalOnWebApplication`和`@ConditionalOnNotWebApplication`注解可以根据应用是否为'web应用'来决定是否包含配置,web应用是任何使用Spring `WebApplicationContext`,定义一个`session`作用域,或有一个`StandardServletEnvironment`的应用。
3 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/70.1 Add a Servlet, Filter or ServletContextListener to an application.md:
--------------------------------------------------------------------------------
1 | ### 70.1 为应用添加Servlet,Filter或Listener
2 |
3 | 这里有两种方式可以为应用添加`Servlet`,`Filter`,`ServletContextListener`和其他Servlet支持的特定listeners。你既可以为它们提供Spring beans,也可以为Servlet组件启用扫描(package scan)。
4 |
--------------------------------------------------------------------------------
/VI. Deploying Spring Boot applications/56.2 Microsoft Windows services.md:
--------------------------------------------------------------------------------
1 | ###56.2 Microsoft Windows服务
2 | 在Window上,你可以使用[winsw](https://github.com/kohsuke/winsw)启动Spring Boot应用。这里有个单独维护的[示例](https://github.com/snicoll-scratches/spring-boot-daemon)为你演示了怎么一步步为Spring Boot应用创建Windows服务。
3 |
--------------------------------------------------------------------------------
/VIII. Build tool plugins/66.1. Repackaging archives.md:
--------------------------------------------------------------------------------
1 | ### 66.1. 重新打包存档
2 |
3 | 使用`org.springframework.boot.loader.tools.Repackager`可以将一个存在的存档重新打包,这样它就变成一个自包含的可执行存档。`Repackager`类需要提供单一的构造器参数,该参数指向一个存在的jar或war包。你可以使用两个可用的`repackage()`方法中的一个来替换原始的文件或写入新的目标,在repackager运行前还可以指定各种配置。
4 |
--------------------------------------------------------------------------------
/III. Using Spring Boot/13.2.3. Changing the Java version.md:
--------------------------------------------------------------------------------
1 | ### 13.2.3. 改变Java版本
2 |
3 | `spring-boot-starter-parent`选择了相当保守的Java兼容策略,如果你遵循我们的建议,使用最新的Java版本,可以添加一个`java.version`属性:
4 | ```xml
5 |
6 | 1.8
7 |
8 | ```
9 |
--------------------------------------------------------------------------------
/III. Using Spring Boot/20.2.6 Known limitations.md:
--------------------------------------------------------------------------------
1 | ###20.2.6 已知限制
2 |
3 | 重启功能不能跟使用标准`ObjectInputStream`反序列化的对象工作,如果需要反序列化数据,你可能需要使用Spring的`ConfigurableObjectInputStream`,并结合`Thread.currentThread().getContextClassLoader()`。
4 |
5 | 不幸的是,一些第三方库反序列化时没有考虑上下文类加载器,如果发现这样的问题,你需要请求原作者给处理下。
6 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/30.5 Solr.md:
--------------------------------------------------------------------------------
1 | ### 30.5 Solr
2 |
3 | [Apache Solr](http://lucene.apache.org/solr/)是一个搜索引擎。Spring Boot为Solr 5客户端library提供基本的自动配置,[Spring Data Solr](https://github.com/spring-projects/spring-data-solr)提供了在它之上的抽象,还有用于收集依赖的`spring-boot-starter-data-solr`'Starter'。
4 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/40. Testing.md:
--------------------------------------------------------------------------------
1 | ###40. 测试
2 |
3 | Spring Boot提供很多有用的工具类和注解用于帮助你测试应用,主要分两个模块:`spring-boot-test`包含核心组件,`spring-boot-test-autoconfigure`为测试提供自动配置。
4 |
5 | 大多数开发者只需要引用`spring-boot-starter-test` ‘Starter’,它既提供Spring Boot测试模块,也提供JUnit,AssertJ,Hamcrest和很多有用的依赖。
6 |
--------------------------------------------------------------------------------
/II. Getting started/10.2. Installing the Spring Boot CLI.md:
--------------------------------------------------------------------------------
1 | ### 10.2. Spring Boot CLI安装
2 |
3 | Spring Boot CLI是一个命令行工具,可用于快速搭建基于Spring的原型。它支持运行[Groovy](http://groovy.codehaus.org/)脚本,这也就意味着你可以使用类似Java的语法,但不用写很多的模板代码。
4 |
5 | Spring Boot不一定非要配合CLI使用,但它绝对是Spring应用取得进展的最快方式(你咋不飞上天呢?)。
6 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/30.7.2 Spring Data Cassandra repositories.md:
--------------------------------------------------------------------------------
1 | ###30.7.2 Spring Data Cassandra仓库
2 | Spring Data包含的仓库对Cassandra提供基本支持,目前受到的限制比先前讨论的JPA仓库要多,并且需要使用`@Query`注解相应的查找方法。
3 |
4 | **注** 想全面了解Spring Data Cassandra,可查看它的[参考指南](http://docs.spring.io/spring-data/cassandra/docs/)。
5 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/40.4.2 EnvironmentTestUtils.md:
--------------------------------------------------------------------------------
1 | ###40.4.2 EnvironmentTestUtils
2 | 使用简单的`key=value`字符串调用`EnvironmentTestUtils`就可以快速添加属性到`ConfigurableEnvironment`或`ConfigurableApplicationContext`:
3 | ```java
4 | EnvironmentTestUtils.addEnvironment(env, "org=Spring", "name=Boot");
5 |
--------------------------------------------------------------------------------
/VII. Spring Boot CLI/58. Installing the CLI.md:
--------------------------------------------------------------------------------
1 | ### 58. 安装CLI
2 |
3 | 你可以手动安装Spring Boot CLI,也可以使用SDKMAN!(SDK管理器)或Homebrew,MacPorts(如果你是一个OSX用户),具体安装指令参考"Getting started"的[Section 10.2, “Installing the Spring Boot CLI” ](../II. Getting started/10.2. Installing the Spring Boot CLI.md)章节。
4 |
--------------------------------------------------------------------------------
/VII. Spring Boot CLI/59.1.3 Default import statements.md:
--------------------------------------------------------------------------------
1 | ###59.1.3 默认import语句
2 |
3 | 为了帮助你减少Groovy代码量,一些`import`语句被自动包含进来了。注意上面的示例中引用`@Component`,`@RestController`和`@RequestMapping`而没有使用全限定名或`import`语句。
4 |
5 | **注**:很多Spring注解在不使用`import`语句的情况下可以正常工作。尝试运行你的应用,看一下在添加imports之前哪些会失败。
6 |
--------------------------------------------------------------------------------
/VIII. Build tool plugins/64.5 Spring Boot plugin configuration.md:
--------------------------------------------------------------------------------
1 | ### 64.5 Spring Boot插件配置
2 |
3 | Gradle插件自动扩展你的构建脚本DSL,它为脚本添加一个`springBoot`元素以此作为Boot插件的全局配置。你可以像配置其他Gradle扩展那样为`springBoot`设置相应的属性(下面有配置选项列表)。
4 | ```gradle
5 | springBoot {
6 | backupSource = false
7 | }
8 | ```
9 |
--------------------------------------------------------------------------------
/III. Using Spring Boot/20.2.2 Watching additional paths.md:
--------------------------------------------------------------------------------
1 | ###20.2.2 查看其他路径
2 |
3 | 如果想让应用在改变没有位于classpath下的文件时也会重启或重新加载,你可以使用`spring.devtools.restart.additional-paths`属性来配置监控变化的额外路径。你可以使用[上面描述](./20.2.1 Excluding resources.md)过的`spring.devtools.restart.exclude`属性去控制额外路径下的变化是否触发一个完整重启或只是一个实时重新加载。
4 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/75.1 Initialize a database using JPA.md:
--------------------------------------------------------------------------------
1 | ### 75.1 使用JPA初始化数据库
2 |
3 | JPA有个生成DDL的特性,并且可以设置为在数据库启动时运行,这可以通过两个外部属性进行控制:
4 |
5 | - `spring.jpa.generate-ddl`(`boolean`)控制该特性的关闭和开启,跟实现者没关系。
6 | - `spring.jpa.hibernate.ddl-auto`(`enum`)是一个Hibernate特性,用于更细力度的控制该行为,更多详情参考以下内容。
7 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/81.2 Create a deployable war file for older servlet containers.md:
--------------------------------------------------------------------------------
1 | ### 81.2 为老的servlet容器创建可部署的war文件
2 |
3 | 老的Servlet容器不支持在Servlet 3.0中使用的`ServletContextInitializer`启动处理。你仍旧可以在这些容器使用Spring和Spring Boot,但你需要为应用添加一个`web.xml`,并将它配置为通过一个`DispatcherServlet`加载一个`ApplicationContext`。
4 |
--------------------------------------------------------------------------------
/III. Using Spring Boot/16.1. Gradually replacing auto-configuration.md:
--------------------------------------------------------------------------------
1 | ### 16.1. 逐步替换自动配置
2 |
3 | 自动配置(Auto-configuration)是非侵入性的,任何时候你都可以定义自己的配置类来替换自动配置的特定部分。例如,如果你添加自己的`DataSource` bean,默认的内嵌数据库支持将不被考虑。
4 |
5 | 如果需要查看当前应用启动了哪些自动配置项,你可以在运行应用时打开`--debug`开关,这将为核心日志开启debug日志级别,并将自动配置相关的日志输出到控制台。
6 |
--------------------------------------------------------------------------------
/III. Using Spring Boot/15. Configuration classes.md:
--------------------------------------------------------------------------------
1 | ### 15. 配置类
2 |
3 | Spring Boot提倡基于Java的配置。尽管你可以使用XML源调用`SpringApplication.run()`,不过还是建议你使用`@Configuration`类作为主要配置源。通常定义了`main`方法的类也是使用`@Configuration`注解的一个很好的替补。
4 |
5 | **注**:虽然网络上有很多使用XML配置的Spring示例,但你应该尽可能的使用基于Java的配置,搜索查看`enable*`注解就是一个好的开端。
6 |
--------------------------------------------------------------------------------
/III. Using Spring Boot/21. Packaging your application for production.md:
--------------------------------------------------------------------------------
1 | ### 21. 打包用于生产的应用
2 |
3 | 可执行jars可用于生产部署。由于它们是自包含的,非常适合基于云的部署。关于其他“生产准备”的特性,比如健康监控,审计和指标REST,或JMX端点,可以考虑添加`spring-boot-actuator`。具体参考[Part V, “Spring Boot Actuator: Production-ready features”](../V. Spring Boot Actuator/README.md)。
4 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/30.8 Couchbase.md:
--------------------------------------------------------------------------------
1 | ###30.8 Couchbase
2 | [Couchbase](http://www.couchbase.com/)是一个基于文档,分布式多模型的开源数据库,设计用于交互式应用程序。Spring Boot为Couchbase提供自动配置,[Spring Data Couchbase](https://github.com/spring-projects/spring-data-couchbase)提供在它之上的抽象,还有收集依赖的`spring-boot-starter-data-couchbase`‘Starter’。
3 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/32. Messaging.md:
--------------------------------------------------------------------------------
1 | ### 32. 消息
2 |
3 | Spring Framework框架为集成消息系统提供了扩展(extensive)支持:从使用`JmsTemplate`简化JMS API,到实现一个能够异步接收消息的完整的底层设施。Spring AMQP提供一个相似的用于'高级消息队列协议'的特征集,并且Spring Boot也为`RabbitTemplate`和RabbitMQ提供了自动配置选项。Spring Websocket提供原生的STOMP消息支持,并且Spring Boot也提供了starters和自动配置支持。
4 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/30.7 Cassandra.md:
--------------------------------------------------------------------------------
1 | ###30.7 Cassandra
2 | [Cassandra](http://cassandra.apache.org/)是一个开源,分布式数据库管理系统,设计用于处理跨很多商品服务器的大数据。Spring Boot为Cassandra提供自动配置,[Spring Data Cassandra](https://github.com/spring-projects/spring-data-cassandra)提供在它之上的抽象,还有收集依赖的`spring-boot-starter-data-cassandra`‘Starter’。
3 |
--------------------------------------------------------------------------------
/III. Using Spring Boot/19.3. Using the Maven plugin.md:
--------------------------------------------------------------------------------
1 | ### 19.3. 使用Maven插件运行
2 |
3 | Spring Boot Maven插件包含一个`run`目标,可用来快速编译和运行应用程序,并且跟在IDE运行一样支持热加载。
4 | ```shell
5 | $ mvn spring-boot:run
6 | ```
7 | 你可以使用一些有用的操作系统环境变量:
8 | ```shell
9 | $ export MAVEN_OPTS=-Xmx1024m -XX:MaxPermSize=128M
10 | ```
11 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/25.3. Profile specific configuration files.md:
--------------------------------------------------------------------------------
1 | ### 25.3. Profile-specific配置文件
2 |
3 | Profile-specific的配置,不管是`application.properties`(或`application.yml`),还是通过`@ConfigurationProperties`引用的文件都是被当作文件来加载的,具体参考[Section 24.3, “Profile specific properties”](24.4. Profile-specific properties.md)。
4 |
--------------------------------------------------------------------------------
/VIII. Build tool plugins/README.md:
--------------------------------------------------------------------------------
1 | ### 构建工具插件
2 |
3 | Spring Boot为Maven和Gradle提供构建工具插件,该插件提供各种各样的特性,包括打包可执行jars。本章节提供关于插件的更多详情及用于扩展一个不支持的构建系统所需的帮助信息。如果你是刚刚开始,那可能需要先阅读[Part III, “Using Spring Boot”](../III. Using Spring Boot/README.md)章节的[“Chapter 13, Build systems”](../III. Using Spring Boot/13. Build systems.md)。
4 |
--------------------------------------------------------------------------------
/X. Appendices/D.1. Nested JARs.md:
--------------------------------------------------------------------------------
1 | ### 附录D.1. 内嵌JARs
2 |
3 | Java没有提供任何标准的方式来加载内嵌的jar文件(也就是jar文件自身包含到一个jar中)。如果你正分发一个在不解压缩的情况下可以从命令行运行的自包含应用,那这将是个问题。
4 |
5 | 为了解决这个问题,很多开发者使用"影子" jars。一个影子jar只是简单的将所有jars的类打包进一个单独的"超级jar"。使用影子jars的问题是它很难分辨在你的应用中实际可以使用的库。在多个jars中存在相同的文件名(内容不同)也是一个问题。Spring Boot另劈稀径,让你能够直接嵌套jars。
6 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/30.1. Redis.md:
--------------------------------------------------------------------------------
1 | ### 30.1. Redis
2 |
3 | [Redis](http://redis.io/)是一个缓存,消息中间件及具有丰富特性的键值存储系统。Spring Boot为[Jedis](https://github.com/xetorthio/jedis/)客户端library提供基本的自动配置,[Spring Data Redis](https://github.com/spring-projects/spring-data-redis)提供了在它之上的抽象,`spring-boot-starter-redis`'Starter'收集了需要的依赖。
4 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/75.4 Initialize a Spring Batch database.md:
--------------------------------------------------------------------------------
1 | ### 75.4 初始化Spring Batch数据库
2 |
3 | 如果你正在使用Spring Batch,那么它会为大多数的流行数据库平台预装SQL初始化脚本。Spring Boot会检测你的数据库类型,并默认执行那些脚本,在这种情况下将关闭快速失败特性(错误被记录但不会阻止应用启动)。这是因为那些脚本是可信任的,通常不会包含bugs,所以错误会被忽略掉,并且对错误的忽略可以让脚本具有幂等性。你可以使用`spring.batch.initializer.enabled=false`显式关闭初始化功能。
4 |
--------------------------------------------------------------------------------
/VII. Spring Boot CLI/59.3 Applications with multiple source files.md:
--------------------------------------------------------------------------------
1 | ### 59.3 多源文件应用
2 |
3 | 你可以在所有接收文件输入的命令中使用shell通配符。这允许你轻松处理来自一个目录下的多个文件,例如:
4 | ```shell
5 | $ spring run *.groovy
6 | ```
7 | 如果想将`test`或`spec`代码从主应用代码中分离,这项技术就十分有用了:
8 | ```shell
9 | $ spring test app/*.groovy test/*.groovy
10 | ```
11 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/27.1.4 MessageCodesResolver.md:
--------------------------------------------------------------------------------
1 | ### 27.1.4 MessageCodesResolver
2 |
3 | Spring MVC有一个实现策略,用于从绑定的errors产生用来渲染错误信息的错误码:`MessageCodesResolver`。Spring Boot会自动为你创建该实现,只要设置`spring.mvc.message-codes-resolver.format`属性为`PREFIX_ERROR_CODE`或`POSTFIX_ERROR_CODE`(具体查看`DefaultMessageCodesResolver.Format`枚举值)。
4 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/46.7 Application information.md:
--------------------------------------------------------------------------------
1 | ###46.7 应用信息
2 | 应用信息会暴露所有[`InfoContributor`](https://github.com/spring-projects/spring-boot/tree/v1.4.1.RELEASE/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/InfoContributor.java) beans收集的各种信息,Spring Boot包含很多自动配置的`InfoContributors`,你也可以编写自己的实现。
3 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/53. Process monitoring.md:
--------------------------------------------------------------------------------
1 | ### 53. 进程监控
2 | 在Spring Boot执行器中,你可以找到几个类,它们创建的文件利于进程监控:
3 | - `ApplicationPidFileWriter`创建一个包含应用PID的文件(默认位于应用目录,文件名为`application.pid`)。
4 | - `EmbeddedServerPortFileWriter`创建一个或多个包含内嵌服务器端口的文件(默认位于应用目录,文件名为`application.port`)。
5 |
6 | 这些writers默认没被激活,但你可以使用以下描述的任何方式来启用它们。
7 |
--------------------------------------------------------------------------------
/II. Getting started/11.3.3. The “main” method.md:
--------------------------------------------------------------------------------
1 | ### 11.3.3. main方法
2 |
3 | 应用程序的最后部分是main方法,这是一个标准的方法,它遵循Java对于一个应用程序入口点的约定。我们的main方法通过调用`run`,将业务委托给了Spring Boot的SpringApplication类。SpringApplication将引导我们的应用,启动Spring,相应地启动被自动配置的Tomcat web服务器。我们需要将`Example.class`作为参数传递给`run`方法,以此告诉SpringApplication谁是主要的Spring组件,并传递args数组以暴露所有的命令行参数。
4 |
--------------------------------------------------------------------------------
/III. Using Spring Boot/14.1. Using the “default” package.md:
--------------------------------------------------------------------------------
1 | ### 14.1. 使用"default"包
2 |
3 | 当类没有声明`package`时,它被认为处于`default package`下。通常不推荐使用`default package`,因为对于使用`@ComponentScan`,`@EntityScan`或`@SpringBootApplication`注解的Spring Boot应用来说,它会扫描每个jar中的类,这会造成一定的问题。
4 |
5 | **注** 我们建议你遵循Java推荐的包命名规范,使用一个反转的域名(例如`com.example.project`)。
6 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/23.9 Application exit.md:
--------------------------------------------------------------------------------
1 | ### 23.9 Application退出
2 |
3 | 为确保`ApplicationContext`在退出时被平静的(gracefully)关闭,每个`SpringApplication`都会注册一个JVM的shutdown钩子,所有标准的Spring生命周期回调(比如`DisposableBean`接口或`@PreDestroy`注解)都能使用。
4 |
5 | 此外,如果想在应用结束时返回特定的退出码(exit code),这些beans可以实现`org.springframework.boot.ExitCodeGenerator`接口。
6 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/70.1.2 Add Servlets, Filters, and Listeners using classpath scanning.md:
--------------------------------------------------------------------------------
1 | ###70.1.2 使用classpath扫描添加Servlets, Filters和Listeners
2 |
3 | 通过把`@ServletComponentScan`注解到一个`@Configuration`类并指定包含要注册组件的package(s),可以将`@WebServlet`,`@WebFilter`和`@WebListener`注解的类自动注册到内嵌servlet容器。默认情况下,`@ServletComponentScan`将从被注解类的package开始扫描。
4 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/71.6 Switch off the Spring MVC DispatcherServlet.md:
--------------------------------------------------------------------------------
1 | ### 71.6 关闭Spring MVC DispatcherServlet
2 |
3 | Spring Boot想要服务来自应用程序root `/`下的所有内容。如果你想将自己的servlet映射到该目录下也是可以的,但当然你可能失去一些Spring Boot MVC特性。为了添加你自己的servlet,并将它映射到root资源,你只需声明一个`Servlet`类型的`@Bean`,并给它特定的bean名称`dispatcherServlet`(如果只想关闭但不替换它,你可以使用该名称创建不同类型的bean)。
4 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/24.2. Accessing command line properties.md:
--------------------------------------------------------------------------------
1 | ### 24.2. 访问命令行属性
2 |
3 | 默认情况下,`SpringApplication`会将所有命令行配置参数(以'--'开头,比如`--server.port=9000`)转化成一个`property`,并将其添加到Spring `Environment`中。正如以上章节提过的,命令行属性总是优先于其他属性源。
4 |
5 | 如果不想将命令行属性添加到`Environment`,你可以使用`SpringApplication.setAddCommandLineProperties(false)`来禁用它们。
6 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/30.6 Elasticsearch.md:
--------------------------------------------------------------------------------
1 | ### 30.6 Elasticsearch
2 |
3 | [Elastic Search](http://www.elasticsearch.org/)是一个开源的,分布式,实时搜索和分析引擎。Spring Boot为Elasticsearch提供基本的自动配置,[Spring Data Elasticsearch](https://github.com/spring-projects/spring-data-elasticsearch)提供在它之上的抽象,还有用于收集依赖的`spring-boot-starter-data-elasticsearch`'Starter'。
4 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/68.4 Build an ApplicationContext hierarchy (adding a parent or root context).md:
--------------------------------------------------------------------------------
1 | ### 68.4 构建ApplicationContext层次结构(添加父或根上下文)
2 |
3 | 你可以使用`ApplicationBuilder`类创建parent/child `ApplicationContext`层次结构,查看'Spring Boot特性'章节的[Section 23.4, “Fluent builder API” ](../IV. Spring Boot features/23.4. Fluent builder API.md)获取更多信息。
4 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/80.11.1 Embedded servlet container compatibility.md:
--------------------------------------------------------------------------------
1 | ### 80.11.1 内嵌Servlet容器兼容性
2 |
3 | 如果你在使用Boot的内嵌Servlet容器,你需要使用一个兼容Java6的容器。Tomcat 7和Jetty 8都是Java 6兼容的。具体参考[Section 70.16 使用Tomcat 7.x或8.0](../IX. ‘How-to’ guides/70.16 Use Tomcat 7.x or 8.0.md)和[Section 70.18 使用Jetty 8](../IX. ‘How-to’ guides/70.18 Use Jetty 8.md)。
4 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/80.11.3 JTA API compatibility.md:
--------------------------------------------------------------------------------
1 | ###80.11.3 JTA API兼容性
2 |
3 | 虽然Java Transaction API自身不要求Java 7,但官方API jar包含的已构建类需要Java 7。如果正在使用JTA,你需要使用能够在Java 6环境工作的jar替换官方的JTA 1.2 API jar。想要实现这样的效果,你需要排除任何`javax.transaction:javax.transaction-api`依赖,并使用`org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:1.0.0.Final`替换它。
4 |
--------------------------------------------------------------------------------
/VIII. Build tool plugins/64.9 Publishing artifacts to a Maven repository using Gradle.md:
--------------------------------------------------------------------------------
1 | ### 64.9 使用Gradle将artifacts发布到Maven仓库
2 |
3 | 如果声明依赖但没有指定版本,且想要将artifacts发布到一个Maven仓库,那你需要使用详细的Spring Boot依赖管理来配置Maven发布。通过配置它发布继承自`spring-boot-starter-parent`的poms或引入来自`spring-boot-dependencies`的依赖管理可以实现该需求。这种配置的具体细节取决于你如何使用Gradle及如何发布该artifacts。
4 |
--------------------------------------------------------------------------------
/X. Appendices/D.6. Alternative single jar solutions.md:
--------------------------------------------------------------------------------
1 | ### 附录D.6. 可替代的单一jar解决方案
2 |
3 | 如果以上限制造成你不能使用Spring Boot Loader,那可以考虑以下的替代方案:
4 |
5 | * [Maven Shade Plugin](http://maven.apache.org/plugins/maven-shade-plugin/)
6 | * [JarClassLoader](http://www.jdotsoft.com/JarClassLoader.php)
7 | * [OneJar](http://one-jar.sourceforge.net/)
8 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/41. WebSockets.md:
--------------------------------------------------------------------------------
1 | ### 41. WebSockets
2 | Spring Boot为内嵌的Tomcat(8和7),Jetty 9和Undertow提供WebSockets自动配置。如果你正在将war包部署到独立容器中,Spring Boot将假设该容器会负责配置WebSocket。Spring框架提供[丰富的WebSocket支持](http://docs.spring.io/spring/docs/4.3.3.RELEASE/spring-framework-reference/htmlsingle/#websocket),只需要添加`spring-boot-starter-websocket`模块即可。
3 |
--------------------------------------------------------------------------------
/III. Using Spring Boot/20.4 Global settings.md:
--------------------------------------------------------------------------------
1 | ###20.4 全局设置
2 |
3 | 在`$HOME`文件夹下添加一个`.spring-boot-devtools.properties`的文件可以用来配置全局的devtools设置(注意文件名以"."开头),添加进该文件的任何属性都会应用到你机器上使用该devtools的Spring Boot应用。例如,想使用触发器文件进行重启,可以添加如下配置:
4 |
5 | ~/.spring-boot-devtools.properties.
6 | ```properties
7 | spring.devtools.reload.trigger-file=.reloadtrigger
8 | ```
9 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/24.6. Using YAML instead of Properties.md:
--------------------------------------------------------------------------------
1 | ### 24.6. 使用YAML代替Properties
2 |
3 | [YAML](http://yaml.org/)是JSON的一个超集,也是一种方便的定义层次配置数据的格式。只要你将[SnakeYAML ](http://code.google.com/p/snakeyaml/)库放到classpath下,`SpringApplication`就会自动支持YAML,以作为properties的替换。
4 |
5 | **注** 如果你使用'Starters',添加`spring-boot-starter`依赖会自动加载SnakeYAML。
6 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/27.1.3 Custom JSON Serializers and Deserializers.md:
--------------------------------------------------------------------------------
1 | ###27.1.3 自定义JSON序列化器和反序列化器
2 |
3 | 如果使用Jackson序列化,反序列化JSON数据,你可能想编写自己的`JsonSerializer`和`JsonDeserializer`类。自定义序列化器(serializers)通常[通过Module注册到Jackson](http://wiki.fasterxml.com/JacksonHowToCustomDeserializers),但Spring Boot提供了`@JsonComponent`注解这一替代方式,它能轻松的将序列化器注册为Spring Beans。
4 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/32.1.4 Using a JNDI ConnectionFactory.md:
--------------------------------------------------------------------------------
1 | ### 32.1.4 使用JNDI ConnectionFactory
2 |
3 | 如果你的App运行在应用服务器中,Spring Boot将尝试使用JNDI定位一个JMS `ConnectionFactory`,默认会检查`java:/JmsXA`和`java:/
4 | XAConnectionFactory`两个地址。如果需要指定替换位置,可以使用`spring.jms.jndi-name`属性:
5 | ```java
6 | spring.jms.jndi-name=java:/MyConnectionFactory
7 | ```
8 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/46.6 Security with HealthIndicators.md:
--------------------------------------------------------------------------------
1 | ### 46.6 安全与HealthIndicators
2 | `HealthIndicators`返回的信息通常有点敏感,例如,你可能不想将数据库服务器的详情发布到外面。因此,在使用一个未认证的HTTP连接时,默认只会暴露健康状态(health status)。如果想将所有的健康信息暴露出去,你可以把`endpoints.health.sensitive`设置为`false`。
3 |
4 | 为防止'拒绝服务'攻击,Health响应会被缓存,你可以使用`endpoints.health.time-to-live`属性改变默认的缓存时间(1000毫秒)。
5 |
--------------------------------------------------------------------------------
/III. Using Spring Boot/19.4. Using the Gradle plugin.md:
--------------------------------------------------------------------------------
1 | ### 19.4. 使用Gradle插件运行
2 |
3 | Spring Boot Gradle插件也包含一个`bootRun`任务,可用来运行你的应用程序。无论你何时import `spring-boot-gradle-plugin`,`bootRun`任务总会被添加进去。
4 | ```shell
5 | $ gradle bootRun
6 | ```
7 | 你可能想使用一些有用的操作系统环境变量:
8 | ```shell
9 | $ export JAVA_OPTS=-Xmx1024m -XX:MaxPermSize=128M
10 | ```
11 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/53.1 Extend configuration.md:
--------------------------------------------------------------------------------
1 | ### 53.1 扩展配置
2 | 在`META-INF/spring.factories`文件中,你可以激活创建PID文件的`listener(s)`,示例:
3 | ```java
4 | org.springframework.context.ApplicationListener=\
5 | org.springframework.boot.actuate.system.ApplicationPidFileWriter,
6 | org.springframework.boot.actuate.system.EmbeddedServerPortFileWriter
7 | ```
8 |
--------------------------------------------------------------------------------
/II. Getting started/10.1. Installation instructions for the Java developer.md:
--------------------------------------------------------------------------------
1 | ### 10.1. 为Java开发者准备的安装指南
2 |
3 | 对于java开发者来说,使用Spring Boot就跟使用其他Java库一样,只需要在你的classpath下引入适当的`spring-boot-*.jar`文件。Spring Boot不需要集成任何特殊的工具,所以你可以使用任何IDE或文本编辑器;同时,Spring Boot应用也没有什么特殊之处,你可以像对待其他Java程序那样运行,调试它。
4 |
5 | 尽管可以拷贝Spring Boot jars,但我们还是建议你使用支持依赖管理的构建工具,比如Maven或Gradle。
6 |
--------------------------------------------------------------------------------
/III. Using Spring Boot/22. What to read next.md:
--------------------------------------------------------------------------------
1 | ### 22. 接下来阅读什么
2 | 现在你应该明白怎么结合最佳实践使用Spring Boot,接下来可以深入学习特殊的部分[Spring Boot features](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/htmlsingle/#boot-features),或者你可以跳过开头,阅读Spring Boot的[production ready](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/htmlsingle/#production-ready)部分。
3 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/79.2.4 Velocity templates.md:
--------------------------------------------------------------------------------
1 | ### 79.2.4 Velocity模板
2 |
3 | 如果你正在使用Velocity,那就将`spring.velocity.cache`设置为`false`,查看[VelocityAutoConfiguration](http://github.com/spring-projects/spring-boot/tree/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/velocity/VelocityAutoConfiguration.java)可以获取其他Velocity自定义选项。
4 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/79.3 Fast application restarts.md:
--------------------------------------------------------------------------------
1 | ###79.3 应用快速重启
2 |
3 | `spring-boot-devtools`模块包括应用自动重启支持,虽然没有其他技术快,比如[JRebel](http://zeroturnaround.com/software/jrebel/)或[Spring Loaded](https://github.com/spring-projects/spring-loaded),但比"冷启动"快。在研究其他复杂重启选项时,你最好自己先试下,更多详情可参考[Chapter 20, Developer tools](../III. Using Spring Boot/20. Developer tools.md)章节。
4 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/80.8 Remote debug a Spring Boot application started with Maven.md:
--------------------------------------------------------------------------------
1 | ### 80.8 远程调试使用Maven启动的Spring Boot项目
2 |
3 | 想要为使用Maven启动的Spring Boot应用添加一个远程调试器,你可以使用[mave插件](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/maven-plugin/)的jvmArguments属性,详情参考[示例](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/maven-plugin/examples/run-debug.html)。
4 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/46.7.4 Build information.md:
--------------------------------------------------------------------------------
1 | ###46.7.4 构建信息
2 | 如果`BuildProperties` bean存在,`info`端点也会发布你的构建信息。
3 |
4 | **注** 如果classpath下存在`META-INF/build-info.properties`文件,Spring Boot将自动构建`BuildProperties` bean。Maven和Gradle都能产生该文件,具体查看[Generate build information](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/htmlsingle/#howto-build-info)。
5 |
--------------------------------------------------------------------------------
/II. Getting started/10.2.3. OSX Homebrew installation.md:
--------------------------------------------------------------------------------
1 | ### 10.2.3. 使用OSX Homebrew进行安装
2 |
3 | 如果你的环境是Mac,并使用[Homebrew](http://brew.sh/),想要安装Spring Boot CLI只需以下操作:
4 | ```shell
5 | $ brew tap pivotal/tap
6 | $ brew install springboot
7 | ```
8 | Homebrew将把spring安装到`/usr/local/bin`下。
9 |
10 | **注**:如果该方案不可用,可能是因为你的brew版本太老了。你只需执行`brew update`并重试即可。
11 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/79.2.1 Thymeleaf templates.md:
--------------------------------------------------------------------------------
1 | ### 79.2.1 Thymeleaf模板
2 |
3 | 如果你正在使用Thymeleaf,那就将`spring.thymeleaf.cache`设置为`false`,查看[ThymeleafAutoConfiguration](http://github.com/spring-projects/spring-boot/tree/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java)可以获取其他Thymeleaf自定义选项。
4 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/47.5 Customizing the management server address.md:
--------------------------------------------------------------------------------
1 | ### 47.5 自定义管理服务器地址
2 | 你可以通过设置`management.address`属性来定义管理端点使用的地址,这在你只想监听内部或面向生产环境的网络,或只监听来自`localhost`的连接时非常有用。
3 |
4 | **注** 如果端口跟主应用服务器不一样,你只能监听一个不同的地址。
5 |
6 | 下面的application.properties示例不允许远程访问管理服务器:
7 | ```java
8 | management.port=8081
9 | management.address=127.0.0.1
10 | ```
11 |
--------------------------------------------------------------------------------
/VIII. Build tool plugins/65.2. spring-boot:findmainclass.md:
--------------------------------------------------------------------------------
1 | ###65.2. spring-boot:findmainclass
2 |
3 | `findmainclass`任务是`exejar`内部用于定位声明`main`方法类的,如果构建需要,你可以直接使用该任务,支持属性如下:
4 |
5 | |属性|描述|是否必需|
6 | |:-----|:-----|:------|
7 | |`classesroot`|Java类文件的根目录|是(除非指定`mainclass`)|
8 | |`mainclass`|可用于缩减`main`类的查找|否|
9 | |`property`|Ant属性必须使用result设值|否(没有指定则result会记录日志中)|
10 |
--------------------------------------------------------------------------------
/VIII. Build tool plugins/65.2.1. Examples.md:
--------------------------------------------------------------------------------
1 | ###65.2.1. 示例
2 | **查找并记录**
3 | ```xml
4 |
5 | ```
6 | **查找并设置**
7 | ```xml
8 |
9 | ```
10 |
11 | **覆盖并设置**
12 | ```xml
13 |
14 | ```
15 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/79.2.2 FreeMarker templates.md:
--------------------------------------------------------------------------------
1 | ### 79.2.2 FreeMarker模板
2 |
3 | 如果你正在使用FreeMarker,那就将`spring.freemarker.cache`设置为`false`,查看[FreeMarkerAutoConfiguration ](http://github.com/spring-projects/spring-boot/tree/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfiguration.java)可以获取其他FreeMarker自定义选项。
4 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/79.2.3 Groovy templates.md:
--------------------------------------------------------------------------------
1 | ### 79.2.3 Groovy模板
2 |
3 | 如果你正在使用Groovy模板,那就将`spring.groovy.template.cache`设置为`false`,查看[GroovyTemplateAutoConfiguration](http://github.com/spring-projects/spring-boot/tree/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfiguration.java)可以获取其他Groovy自定义选项。
4 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/README.md:
--------------------------------------------------------------------------------
1 | ### Spring Boot特性
2 |
3 | 本章节将深入详细的介绍Spring Boot,通过阅读本节你可以了解到需要使用和定制的核心特性。如果没做好准备,你可以先阅读[Part II. Getting started](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/htmlsingle/#getting-started)和[Part III, “Using Spring Boot” ](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/htmlsingle/#using-boot)章节,以对Spring Boot有个良好的基本认识。
4 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/79.4 Reload Java classes without restarting the container.md:
--------------------------------------------------------------------------------
1 | ### 79.4 在不重启容器的情况下重新加载Java类
2 |
3 | 现代IDEs(Eclipse, IDEA等)都支持字节码的热交换,所以如果你做了一个没有影响类或方法签名的改变,它会利索地重新加载并没有任何影响。
4 |
5 | [Spring Loaded](https://github.com/spring-projects/spring-loaded)在这方面走的更远,它能够重新加载方法签名改变的类定义,如果对它进行一些自定义配置可以强制`ApplicationContext`刷新自己(但没有通用的机制来确保这对一个运行中的应用总是安全的,所以它可能只是一个开发时的技巧)。
6 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/README.md:
--------------------------------------------------------------------------------
1 | ### How-to指南
2 |
3 | 本章节将回答一些常见的"我该怎么做"类型的问题,这些问题在我们使用Spring Boot时经常遇到。这虽然不是一个详尽的列表,但它覆盖了很多方面。
4 |
5 | 如果遇到一个特殊的我们没有覆盖的问题,你可以查看[stackoverflow.com](http://stackoverflow.com/tags/spring-boot),看是否已经有人给出了答案;这也是一个很好的提新问题的地方(请使用`spring-boot`标签)。
6 |
7 | 我们也乐意扩展本章节;如果想添加一个'how-to',你可以给我们发一个[pull请求](http://github.com/spring-projects/spring-boot/tree/master)。
8 |
--------------------------------------------------------------------------------
/III. Using Spring Boot/20.3 LiveReload.md:
--------------------------------------------------------------------------------
1 | ###20.3 LiveReload
2 |
3 | `spring-boot-devtools`模块包含一个内嵌的LiveReload服务器,它可以在资源改变时触发浏览器刷新。LiveReload浏览器扩展可以免费从[livereload.com](http://livereload.com/extensions/)站点获取,支持Chrome,Firefox,Safari等浏览器。
4 |
5 | 如果不想在运行应用时启动LiveReload服务器,你可以将`spring.devtools.livereload.enabled`属性设置为false。
6 |
7 | **注** 每次只能运行一个LiveReload服务器,如果你在IDE中启动多个应用,只有第一个能够获得动态加载功能。
8 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/27. Developing web applications.md:
--------------------------------------------------------------------------------
1 | ### 27. 开发Web应用
2 | Spring Boot非常适合开发web应用程序。你可以使用内嵌的Tomcat,Jetty或Undertow轻轻松松地创建一个HTTP服务器。大多数的web应用都可以使用`spring-boot-starter-web`模块进行快速搭建和运行。
3 |
4 | 如果没有开发过Spring Boot web应用,可以参考[Getting started章节](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/htmlsingle/#getting-started-first-application)的"Hello World!"示例。
5 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/32.1. JMS.md:
--------------------------------------------------------------------------------
1 | ### 32.1. JMS
2 | `javax.jms.ConnectionFactory`接口提供标准的用于创建`javax.jms.Connection`的方法,`javax.jms.Connection`用于和JMS代理(broker)交互。
3 | 尽管Spring需要一个`ConnectionFactory`才能使用JMS,通常你不需要直接使用它,而是依赖于上层消息抽象(具体参考Spring框架的[相关章节](http://docs.spring.io/spring/docs/4.1.4.RELEASE/spring-framework-reference/htmlsingle/#jms)),Spring Boot会自动配置发送和接收消息需要的设施(infrastructure)。
4 |
--------------------------------------------------------------------------------
/VIII. Build tool plugins/66. Supporting other build systems.md:
--------------------------------------------------------------------------------
1 | ### 66. 对其他构建系统的支持
2 |
3 | 如果想使用除了Maven和Gradle之外的构建工具,你可能需要开发自己的插件。可执行jars需要遵循一个特定格式,并且一些实体需要以不压缩的方式写入(详情查看附录中的[可执行jar格式](http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#executable-jar)章节)。
4 |
5 | Spring Boot Maven和Gradle插件在实际生成jars的过程中会使用`spring-boot-loader-tools`,如果需要,你也可以自由地使用该library。
6 |
--------------------------------------------------------------------------------
/VIII. Build tool plugins/67. What to read next.md:
--------------------------------------------------------------------------------
1 | ### 67. 接下来阅读什么
2 |
3 | 如果对构建工具插件如何工作感兴趣,你可以查看GitHub上的[spring-boot-tools](https://github.com/spring-projects/spring-boot/tree/v1.4.1.RELEASE/spring-boot-tools)模块,附加中有详细的[可执行jar格式](https://github.com/spring-projects/spring-boot/tree/v1.4.1.RELEASE/spring-boot-tools)。
4 |
5 | 如果有特定构建相关的问题,可以查看[how-to](../IX. ‘How-to’ guides/README.md)指南。
6 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/30.3.2 Using the embedded mode.md:
--------------------------------------------------------------------------------
1 | ### 30.3.2 使用内嵌模式
2 |
3 | **注** Neo4j的内嵌模式从属于不同的许可,在将它集成到应用之前确保复查下。
4 |
5 | 如果将`org.neo4j:neo4j-ogm-embedded-driver`依赖添加到应用中,Spring Boot会自动配置一个进程内(in-process)的内嵌Neo4j实例,当应用关闭时,该实例不会持久化任何数据。设置`spring.data.neo4j.embedded.enabled=false`可显式关闭该模式,你也可以启用内嵌模式的持久化特性:
6 | ```properties
7 | spring.data.neo4j.uri=file://var/tmp/graph.db
8 | ```
9 |
--------------------------------------------------------------------------------
/VIII. Build tool plugins/63. Spring Boot Maven plugin.md:
--------------------------------------------------------------------------------
1 | ### 63. Spring Boot Maven插件
2 |
3 | [Spring Boot Maven插件](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/maven-plugin/)为Maven提供Spring Boot支持,它允许你打包可执行jar或war存档,然后就地运行应用。为了使用它,你需要使用Maven 3.2(或更高版本)。
4 |
5 | **注** 参考[Spring Boot Maven Plugin Site](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/maven-plugin/)可以获取全部的插件文档。
6 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/30.5.2 Spring Data Solr repositories.md:
--------------------------------------------------------------------------------
1 |
2 | ### 30.5.2 Spring Data Solr仓库
3 |
4 | Spring Data包含的仓库也支持Apache Solr,正如先前讨论的JPA仓库,基于方法名自动创建查询是基本的原则。
5 |
6 | 实际上,不管是Spring Data JPA还是Spring Data Solr都共享相同的基础设施。所以你可以使用先前的JPA示例,并假设那个`City`现在是一个`@SolrDocument`类而不是JPA `@Entity`,它将以同样的方式工作。
7 |
8 | **注** 具体参考[Spring Data Solr文档](http://projects.spring.io/spring-data-solr/)。
9 |
--------------------------------------------------------------------------------
/II. Getting started/9. System Requirements.md:
--------------------------------------------------------------------------------
1 | ### 9. 系统要求
2 |
3 | 默认情况下,Spring Boot 1.4.0.BUILD-SNAPSHOT 需要[Java7](http://www.java.com/)环境,Spring框架4.3.2.BUILD-SNAPSHOT或以上版本。你可以在Java6下使用Spring Boot,不过需要添加额外配置。具体参考[Section 82.11, “How to use Java 6” ](../IX. ‘How-to’ guides/73.9. How to use Java 6.md)。明确提供构建支持的有Maven(3.2+)和Gradle(1.12+)。
4 |
5 | **注**:尽管你可以在Java6或Java7环境下使用Spring Boot,通常建议尽可能使用Java8。
6 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/77.3 Actuator and Jersey.md:
--------------------------------------------------------------------------------
1 | ###77.3 Actuator和Jersey
2 |
3 | 执行器HTTP端点只有在基于Spring MVC的应用才可用,如果想使用Jersey和执行器,你需要启用Spring MVC(添加`spring-boot-starter-web`依赖)。默认情况下,Jersey和 Spring MVC分发器servlet被映射到相同路径(`/`)。你需要改变它们中的某个路径(Spring MVC可以配置`server.servlet-path`,Jersey可以配置`spring.jersey.application-path`)。例如,如果你在`application.properties`中添加`server.servlet-path=/system`,你将在`/system`访问执行器HTTP端点。
4 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/48.3 Using Jolokia for JMX over HTTP.md:
--------------------------------------------------------------------------------
1 | ### 48.3 使用Jolokia通过HTTP实现JMX远程管理
2 | Jolokia是一个JMX-HTTP桥,它提供了一种访问JMX beans的替代方法。想要使用Jolokia,只需添加`org.jolokia:jolokia-core`的依赖。例如,使用Maven需要添加以下配置:
3 | ```xml
4 |
5 | org.jolokia
6 | jolokia-core
7 |
8 | ```
9 | 然后在你的管理HTTP服务器上可以通过`/jolokia`访问Jolokia。
10 |
--------------------------------------------------------------------------------
/II. Getting started/10.3. Upgrading from an earlier version of Spring Boot.md:
--------------------------------------------------------------------------------
1 | ### 10.3. 版本升级
2 |
3 | 如果你正在升级Spring Boot的早期发布版本,那最好查看下[project wiki](http://github.com/spring-projects/spring-boot/wiki)上的"release notes",你会发现每次发布对应的升级指南和一个"new and noteworthy"特性列表。
4 |
5 | 想要升级一个已安装的CLI,你需要使用合适的包管理命令,例如`brew upgrade`;如果是手动安装CLI,按照[standard instructions](10.2.1. Manual installation.md)操作并记得更新你的PATH环境变量以移除任何老的引用。
6 |
--------------------------------------------------------------------------------
/II. Getting started/9.1. Servlet containers.md:
--------------------------------------------------------------------------------
1 | ### 9.1. Servlet容器
2 |
3 | 下列内嵌容器支持开箱即用(out of the box):
4 |
5 | |名称|Servlet版本|Java版本|
6 | |--------|:-------|:-------|
7 | |Tomcat 8|3.1|Java 7+|
8 | |Tomcat 7|3.0|Java 6+|
9 | |Jetty 9.3|3.1|Java 8+|
10 | |Jetty 9.2|3.1|Java 7+|
11 | |Jetty 8|3.0|Java 6+|
12 | |Undertow 1.3|3.1|Java 7+|
13 |
14 | 你也可以将Spring Boot应用部署到任何兼容Servlet 3.0+的容器。
15 |
--------------------------------------------------------------------------------
/III. Using Spring Boot/16. Auto-configuration.md:
--------------------------------------------------------------------------------
1 | ### 16. 自动配置
2 |
3 | Spring Boot自动配置(auto-configuration)尝试根据添加的jar依赖自动配置你的Spring应用。例如,如果classpath下存在`HSQLDB`,并且你没有手动配置任何数据库连接的beans,那么Spring Boot将自动配置一个内存型(in-memory)数据库。
4 |
5 | 实现自动配置有两种可选方式,分别是将`@EnableAutoConfiguration`或`@SpringBootApplication`注解到`@Configuration`类上。
6 |
7 | **注**:你应该只添加一个`@EnableAutoConfiguration`注解,通常建议将它添加到主配置类(primary `@Configuration`)上。
8 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/74.4 Separate @Entity definitions from Spring configuration.md:
--------------------------------------------------------------------------------
1 | ### 74.4 从Spring配置分离`@Entity`定义
2 |
3 | Spring Boot会基于它找到的`@EnableAutoConfiguration`来尝试猜测`@Entity`定义的位置,想要获取更多控制可以使用`@EntityScan`注解,比如:
4 | ```java
5 | @Configuration
6 | @EnableAutoConfiguration
7 | @EntityScan(basePackageClasses=City.class)
8 | public class Application {
9 |
10 | //...
11 |
12 | }
13 | ```
14 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/README.md:
--------------------------------------------------------------------------------
1 | ### Spring Boot执行器:Production-ready特性
2 |
3 | Spring Boot包含很多其他特性,可用来帮你监控和管理发布到生产环境的应用。你可以选择使用HTTP端点,JMX,甚至通过远程shell(SSH或Telnet)来管理和监控应用。审计(Auditing),健康(health)和数据采集(metrics gathering)会自动应用到你的应用。
4 |
5 | Actuator HTTP端点只能用在基于Spring MVC的应用,特别地,它不能跟Jersey一块使用,除非你也[启用Spring MVC](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/htmlsingle/#howto-use-actuator-with-jersey)。
6 |
--------------------------------------------------------------------------------
/VII. Spring Boot CLI/59.1.2 Deduced “grab” coordinates.md:
--------------------------------------------------------------------------------
1 | ###59.1.2 推断"grab"坐标
2 | Spring Boot扩展了Groovy标准`@Grab`注解,使其能够允许你指定一个没有`group`或`version`的依赖,例如`@Grab('freemarker')`。Spring Boot使用默认依赖元数据推断artifact’s的group和version,需要注意的是默认元数据和你使用的CLI版本有绑定关系-只有在迁移到新版本的CLI时它才会改变,这样你就可以控制何时改变依赖了,在[附录](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/htmlsingle/#appendix-dependency-versions)的表格中可以查看默认元数据包含的依赖和它们的版本。
3 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/24.7.3 Properties conversion.md:
--------------------------------------------------------------------------------
1 | ### 24.7.3 属性转换
2 |
3 | 将外部应用配置绑定到`@ConfigurationProperties` beans时,Spring会尝试将属性强制转换为正确的类型。如果需要自定义类型转换器,你可以提供一个`ConversionService` bean(bean id为`conversionService`),或自定义属性编辑器(通过`CustomEditorConfigurer` bean),或自定义`Converters`(bean定义时需要注解`@ConfigurationPropertiesBinding`)。
4 |
5 | **注** 由于该bean在应用程序生命周期的早期就需要使用,所以确保限制你的`ConversionService`使用的依赖。通常,在创建时期任何你需要的依赖可能都没完全初始化。
6 |
--------------------------------------------------------------------------------
/III. Using Spring Boot/20.5 Remote applications.md:
--------------------------------------------------------------------------------
1 | ###20.5 远程应用
2 |
3 | Spring Boot开发者工具并不仅限于本地开发,在运行远程应用时你也可以使用一些特性。远程支持是可选的,通过设置`spring.devtools.remote.secret`属性可以启用它,例如:
4 | ```properties
5 | spring.devtools.remote.secret=mysecret
6 | ```
7 | **注** 在远程应用上启用`spring-boot-devtools`有一定的安全风险,生产环境中最好不要使用。
8 |
9 | 远程devtools支持分两部分:一个是接收连接的服务端端点,另一个是运行在IDE里的客户端应用。如果设置`spring.devtools.remote.secret`属性,服务端组件会自动启用,客户端组件必须手动启动。
10 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/52.1 Custom tracing.md:
--------------------------------------------------------------------------------
1 | ### 52.1 自定义追踪
2 | 如果需要追踪其他事件,你可以注入[TraceRepository](http://github.com/spring-projects/spring-boot/tree/master/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/trace/TraceRepository.java)到你的Spring Beans中,`add`方法接收一个`Map`结构的参数,该数据将转换为JSON并被记录下来。
3 |
4 | 默认使用`InMemoryTraceRepository`存储最新的100个事件,如果需要扩充容量,你可以定义自己的`InMemoryTraceRepository`实例,甚至创建自己的`TraceRepository`实现。
5 |
--------------------------------------------------------------------------------
/VII. Spring Boot CLI/61. Configuring the CLI with settings.xml.md:
--------------------------------------------------------------------------------
1 | ### 61. 使用settings.xml配置CLI
2 | Spring Boot CLI使用Maven的依赖解析引擎Aether来解析依赖,它充分利用发现的`~/.m2/settings.xml` Maven设置去配置Aether。
3 |
4 | CLI支持以下配置:
5 |
6 | * Offline
7 | * Mirrors
8 | * Servers
9 | * Proxies
10 | * Profiles
11 | * Activation
12 |
13 | * Repositories
14 | * Active profiles
15 |
16 | 更多信息可参考[Maven设置文档](https://maven.apache.org/settings.html)。
17 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/70.16.2 Use Tomcat 7.x or 8.0 with Gradle.md:
--------------------------------------------------------------------------------
1 | ### 70.16.2 通过Gradle使用Tomcat7.x或8.0
2 |
3 | 对于Gradle,你可以通过设置`tomcat.version`属性改变Tomcat的版本,然后添加`tomcat-juli`依赖:
4 | ```gradle
5 | ext['tomcat.version'] = '7.0.59'
6 | dependencies {
7 | compile 'org.springframework.boot:spring-boot-starter-web'
8 | compile group:'org.apache.tomcat', name:'tomcat-juli', version:property('tomcat.version')
9 | }
10 | ```
11 |
--------------------------------------------------------------------------------
/II. Getting started/11.3.2. The @EnableAutoConfiguration annotation.md:
--------------------------------------------------------------------------------
1 | ### 11.3.2. @EnableAutoConfiguration注解
2 |
3 | 第二个类级别的注解是`@EnableAutoConfiguration`,这个注解告诉Spring Boot根据添加的jar依赖猜测你想如何配置Spring。由于`spring-boot-starter-web`添加了Tomcat和Spring MVC,所以auto-configuration将假定你正在开发一个web应用,并对Spring进行相应地设置。
4 |
5 | **Starters和Auto-Configuration**:Auto-configuration设计成可以跟"Starters"一起很好的使用,但这两个概念没有直接的联系。你可以自由地挑选starters以外的jar依赖,Spring Boot仍会尽最大努力去自动配置你的应用。
6 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/30.6.3 Spring Data Elasticsearch repositories.md:
--------------------------------------------------------------------------------
1 | ### 30.6.3 Spring Data Elasticseach仓库
2 |
3 | Spring Data包含的仓库也支持Elasticsearch,正如前面讨论的JPA仓库,基于方法名自动创建查询是基本的原则。
4 |
5 | 实际上,不管是Spring Data JPA还是Spring Data Elasticsearch都共享相同的基础设施。所以你可以使用前面的JPA示例,并假设那个`City`现在是一个Elasticsearch `@Document`类而不是JPA `@Entity`,它将以同样的方式工作。
6 |
7 | **注** 具体参考[Spring Data Elasticsearch文档](http://docs.spring.io/spring-data/elasticsearch/docs/)。
8 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/70.12 Configure Jetty.md:
--------------------------------------------------------------------------------
1 |
2 | ### 70.12 配置Jetty
3 |
4 | 通常你可以遵循[Section 69.8, “Discover built-in options for external properties”](./69.8 Discover built-in options for external properties.md)关于`@ConfigurationProperties`(此处主要是`ServerProperties`)的建议,但也要看下`EmbeddedServletContainerCustomizer`。
5 |
6 | Jetty API相当丰富,一旦获取到`JettyEmbeddedServletContainerFactory`,你就可以使用很多方式修改它,或更彻底地就是添加你自己的`JettyEmbeddedServletContainerFactory`。
7 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/48.1 Customizing MBean names.md:
--------------------------------------------------------------------------------
1 | ### 48.1 自定义MBean名称
2 | MBean的名称通常产生于端点的id,例如,`health`端点被暴露为`org.springframework.boot/Endpoint/healthEndpoint`。
3 |
4 | 如果应用包含多个Spring `ApplicationContext`,你会发现存在名称冲突。为了解决这个问题,你可以将`endpoints.jmx.uniqueNames`设置为`true`,这样MBean的名称总是唯一的。
5 |
6 | 你也可以自定义端点暴露的JMX域,具体可参考以下`application.properties`示例:
7 | ```properties
8 | endpoints.jmx.domain=myapp
9 | endpoints.jmx.uniqueNames=true
10 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/24.5. Placeholders in properties.md:
--------------------------------------------------------------------------------
1 | ### 24.5. 属性占位符
2 |
3 | 当使用`application.properties`定义的属性时,Spring会先通过已经存在的`Environment`查找该属性,所以你可以引用事先定义的值(比如,系统属性):
4 | ```java
5 | app.name=MyApp
6 | app.description=${app.name} is a Spring Boot application
7 | ```
8 | **注** 你也可以使用该技巧为存在的Spring Boot属性创建'短'变量,具体参考[Section 69.4, “Use ‘short’ command line arguments”](../IX. ‘How-to’ guides/63.3. Use ‘short’ command line arguments.md)。
9 |
--------------------------------------------------------------------------------
/II. Getting started/10. Installing Spring Boot.md:
--------------------------------------------------------------------------------
1 | ### 10. Spring Boot安装
2 |
3 | Spring Boot可以跟经典的Java开发工具(Eclipse,IntelliJ等)一起使用或安装成一个命令行工具。不管怎样,你都需要安装[Java SDK v1.6 ](http://www.java.com/)或更高版本。在开始之前,你需要检查下当前安装的Java版本:
4 | ```shell
5 | $ java -version
6 | ```
7 | 如果你是一个Java新手,或只是想体验一下Spring Boot,你可能想先尝试[Spring Boot CLI](10.2. Installing the Spring Boot CLI.md),否则继续阅读“经典”地安装指南。
8 |
9 | **注**:尽管Spring Boot兼容Java 1.6,如果可能的话,你应该考虑使用Java最新版本。
10 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/79.1 Reload static content.md:
--------------------------------------------------------------------------------
1 | ### 79.1 重新加载静态内容
2 |
3 | Spring Boot有很多用于热加载的选项,不过推荐使用[spring-boot-devtools](../III. Using Spring Boot/20. Developer tools.md),因为它提供了其他开发时特性,比如快速应用重启和LiveReload,还有开发时敏感的配置加载(比如,模板缓存)。
4 |
5 |
6 | 此外,使用IDE开发也是一个不错的方式,特别是需要调试的时候(所有的现代IDEs都允许重新加载静态资源,通常也支持对变更的Java类进行热交换)。
7 |
8 | 最后,[Maven和Gradle插件](../VIII. Build tool plugins/README.md)也支持命令行下的静态文件热加载。如果你使用其他高级工具编写css/js,并使用外部的css/js编译器,那你就可以充分利用该功能。
9 |
--------------------------------------------------------------------------------
/III. Using Spring Boot/19.2. Running as a packaged application.md:
--------------------------------------------------------------------------------
1 | ### 19.2. 作为一个打包后的应用运行
2 |
3 | 如果使用Spring Boot Maven或Gradle插件创建一个可执行jar,你可以使用`java -jar`运行应用。例如:
4 | ```shell
5 | $ java -jar target/myproject-0.0.1-SNAPSHOT.jar
6 | ```
7 | Spring Boot支持以远程调试模式运行一个打包的应用,下面的命令可以为应用关联一个调试器:
8 | ```shell
9 | $ java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n \
10 | -jar target/myproject-0.0.1-SNAPSHOT.jar
11 | ```
12 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/30.6.1 Connecting to Elasticsearch using Jest.md:
--------------------------------------------------------------------------------
1 | ### 30.6.1 使用Jest连接Elasticsearch
2 | 如果添加`Jest`依赖,你可以注入一个自动配置的`JestClient`,默认目标为`http://localhost:9200/`,也可以进一步配置该客户端:
3 | ```properties
4 | spring.elasticsearch.jest.uris=http://search.example.com:9200
5 | spring.elasticsearch.jest.read-timeout=10000
6 | spring.elasticsearch.jest.username=user
7 | spring.elasticsearch.jest.password=secret
8 | ```
9 | 定义一个`JestClient` bean以完全控制注册过程。
10 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/50.8.4 Export to JMX.md:
--------------------------------------------------------------------------------
1 | ###50.8.4 示例: 导出到JMX
2 | 如果提供一个`JmxMetricWriter`类型并注解`@ExportMetricWriter`的`@Bean`,指标将作为MBeans暴露到本地服务器(只要开启,Spring Boot JMX自动配置会提供`MBeanExporter`)。
3 |
4 | 示例:
5 | ```java
6 | @Bean
7 | @ExportMetricWriter
8 | MetricWriter metricWriter(MBeanExporter exporter) {
9 | return new JmxMetricWriter(exporter);
10 | }
11 | ```
12 | 每个指标都暴露为单独的MBean,你可以将`ObjectNamingStrategy`注入`JmxMetricWriter`来指定`ObjectNames`的格式。
13 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/27.1.9 Spring HATEOAS.md:
--------------------------------------------------------------------------------
1 | ### 27.1.9 Spring HATEOAS
2 |
3 | 如果正在开发基于超媒体的RESTful API,你可能需要Spring HATEOAS,而Spring Boot会为其提供自动配置,这在大多数应用中都运作良好。
4 | 自动配置取代了`@EnableHypermediaSupport`,只需注册一定数量的beans就能轻松构建基于超媒体的应用,这些beans包括`LinkDiscoverers`(客户端支持),`ObjectMapper`(用于将响应编排为想要的形式)。`ObjectMapper`可以根据`spring.jackson.*`属性或`Jackson2ObjectMapperBuilder` bean进行自定义。
5 |
6 | 通过注解`@EnableHypermediaSupport`,你可以控制Spring HATEOAS的配置,但这会禁用上述`ObjectMapper`的自定义功能。
7 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/70.7 Use behind a front-end proxy server.md:
--------------------------------------------------------------------------------
1 | ###70.7 在前端代理服务器后使用
2 |
3 | 你的应用可能需要发送`302`跳转或使用指向自己的绝对路径渲染内容。当在代理服务器后面运行时,调用者需要的是代理服务器链接而不是部署应用的实际物理机器地址,通常的解决方式是代理服务器将前端地址放到headers并告诉后端服务器如何拼装链接。
4 |
5 | 如果代理添加约定的`X-Forwarded-For`和`X-Forwarded-Proto` headers(大多数都是开箱即用的),只要将`application.properties`中的`server.use-forward-headers`设置为`true`,绝对链接就能正确的渲染。
6 |
7 | **注** 如果应用运行在Cloud Foundry或Heroku,`server.use-forward-headers`属性没指定的话默认为`true`,其他实例默认为`false`。
8 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/51. Auditing.md:
--------------------------------------------------------------------------------
1 | ### 51. 审计
2 | Spring Boot执行器有一个灵活的审计框架,一旦Spring Security处于活动状态(默认抛出'authentication success','failure'和'access denied'异常),它就会发布事件。这对于报告非常有用,同时可以基于认证失败实现一个锁定策略。为了自定义发布的安全事件,你可以提供自己的`AbstractAuthenticationAuditListener`,`AbstractAuthorizationAuditListener`实现。你也可以使用审计服务处理自己的业务事件。为此,你可以将存在的`AuditEventRepository`注入到自己的组件,并直接使用它,或者只是简单地通过Spring `ApplicationEventPublisher`发布`AuditApplicationEvent`(使用`ApplicationEventPublisherAware`)。
3 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/39. Monitoring and management over JMX.md:
--------------------------------------------------------------------------------
1 | ###39. 基于JMX的监控和管理
2 |
3 | Java管理扩展(JMX)提供了一个标准的用于监控和管理应用的机制。默认情况下,Spring Boot将创建一个id为‘mbeanServer’的`MBeanServer`,并导出任何被Spring JMX注解(`@ManagedResource`,`@ManagedAttribute`,`@ManagedOperation`)的beans,具体参考[JmxAutoConfiguration类](https://github.com/spring-projects/spring-boot/tree/v1.4.1.RELEASE/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jmx/JmxAutoConfiguration.java)。
4 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/74.8 Use a traditional persistence.xml.md:
--------------------------------------------------------------------------------
1 | ### 74.8 使用普通的persistence.xml
2 |
3 | Spring不要求使用XML配置JPA提供者(provider),并且Spring Boot假定你想要充分利用该特性。如果你倾向于使用`persistence.xml`,那你需要定义你自己的id为`entityManagerFactory`的`LocalEntityManagerFactoryBean`类型的`@Bean`,并在那设置持久化单元的名称,默认设置可查看[JpaBaseConfiguration](https://github.com/spring-projects/spring-boot/blob/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java)。
4 |
--------------------------------------------------------------------------------
/III. Using Spring Boot/20.2.3 Disabling restart.md:
--------------------------------------------------------------------------------
1 | ###20.2.3 禁用重启
2 |
3 | 如果不想使用重启特性,你可以通过`spring.devtools.restart.enabled`属性来禁用它,通常情况下可以在`application.properties`文件中设置(依旧会初始化重启类加载器,但它不会监控文件变化)。
4 |
5 | 如果需要彻底禁用重启支持,比如,不能跟某个特殊库一块工作,你需要在调用`SpringApplication.run(…)`之前设置一个系统属性,如下:
6 | ```java
7 | public static void main(String[] args) {
8 | System.setProperty("spring.devtools.restart.enabled", "false");
9 | SpringApplication.run(MyApp.class, args);
10 | }
11 | ```
12 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/29.1.3. Connection to a JNDI DataSource.md:
--------------------------------------------------------------------------------
1 | ### 29.1.3. 连接JNDI数据库
2 |
3 | 如果正在将Spring Boot应用部署到一个应用服务器,你可能想要用应用服务器内建的特性来配置和管理你的DataSource,并使用JNDI访问它。
4 |
5 | `spring.datasource.jndi-name`属性可用来替代`spring.datasource.url`,`spring.datasource.username`和`spring.datasource.password`去从一个特定的JNDI路径获取`DataSource`,比如,以下`application.properties`中的片段展示了如何获取JBoss AS定义的`DataSource`:
6 | ```java
7 | spring.datasource.jndi-name=java:jboss/datasources/customers
8 | ```
9 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/30.5.1 Connecting to Solr.md:
--------------------------------------------------------------------------------
1 | ### 30.5.1 连接Solr
2 |
3 | 你可以注入一个自动配置的`SolrClient`实例,就像其他Spring beans那样,该实例默认使用`localhost:8983/solr`连接Solr服务器:
4 | ```java
5 | @Component
6 | public class MyBean {
7 |
8 | private SolrClient solr;
9 |
10 | @Autowired
11 | public MyBean(SolrClient solr) {
12 | this.solr = solr;
13 | }
14 |
15 | // ...
16 |
17 | }
18 | ```
19 | 如果你添加自己的`SolrClient`类型的`@Bean`,它将会替换默认实例。
20 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/68.5 Create a non-web application.md:
--------------------------------------------------------------------------------
1 | ### 68.5 创建no-web应用
2 |
3 | 不是所有的Spring应用都必须是web应用(或web服务)。如果你想在`main`方法中执行一些代码,但需要启动一个Spring应用去设置需要的底层设施,那使用Spring Boot的`SpringApplication`特性可以很容易实现。`SpringApplication`会根据它是否需要一个web应用来改变它的`ApplicationContext`类,首先你需要做的是去掉servlet API依赖,如果不能这样做(比如基于相同的代码运行两个应用),那你可以明确地调用`SpringApplication.setWebEnvironment(false)`或设置`applicationContextClass`属性(通过Java API或使用外部配置)。你想运行的,作为业务逻辑的应用代码可以实现为一个`CommandLineRunner`,并将上下文降级为一个`@Bean`定义。
4 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/70.8 Configure Tomcat.md:
--------------------------------------------------------------------------------
1 | ### 70.8 配置Tomcat
2 |
3 | 通常你可以遵循[Section 69.8, “Discover built-in options for external properties”](./69.8 Discover built-in options for external properties.md)关于`@ConfigurationProperties`(这里主要的是`ServerProperties`)的建议,但也看下`EmbeddedServletContainerCustomizer`和各种你可以添加的Tomcat-specific的`*Customizers`。
4 |
5 | Tomcat APIs相当丰富,一旦获取到`TomcatEmbeddedServletContainerFactory`,你就能够以多种方式修改它,或更彻底地就是添加你自己的`TomcatEmbeddedServletContainerFactory`。
6 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/73.2.1 Use YAML or JSON to configure Log4j 2.md:
--------------------------------------------------------------------------------
1 | ### 73.2.1 使用YAML或JSON配置Log4j2
2 |
3 | 除了它的默认XML配置格式,Log4j 2也支持YAML和JSON配置文件。想使用其他配置文件格式配置Log4j 2,你需要添加合适的依赖到classpath,并以匹配所选格式的方式命名配置文件:
4 |
5 | |格式|依赖|文件名|
6 | |:----|:----|:---|
7 | |YAML|`com.fasterxml.jackson.core:jackson-databind` `com.fasterxml.jackson.dataformat:jackson-dataformat-yaml`|`log4j2.yaml` `log4j2.yml`|
8 | |JSON|`com.fasterxml.jackson.core:jackson-databind`|`log4j2.json` `log4j2.jsn`|
9 |
--------------------------------------------------------------------------------
/III. Using Spring Boot/20.2.4 Using a trigger file.md:
--------------------------------------------------------------------------------
1 | ###20.2.4 使用触发器文件
2 |
3 | 如果使用一个IDE连续不断地编译变化的文件,你可能倾向于只在特定时间触发重启,触发器文件可以帮你实现该功能。触发器文件是一个特殊的文件,只有修改它才能实际触发一个重启检测。改变该文件只会触发检测,实际的重启只会在Devtools发现它必须这样做的时候,触发器文件可以手动更新,也可以通过IDE插件更新。
4 |
5 | 使用`spring.devtools.restart.trigger-file`属性可以指定触发器文件。
6 |
7 | **注** 你可能想将`spring.devtools.restart.trigger-file`属性设置为[全局设置](http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#using-boot-devtools-globalsettings),这样所有的工程表现都会相同。
8 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/24.7.1. Third-party configuration.md:
--------------------------------------------------------------------------------
1 | ### 24.7.1. 第三方配置
2 |
3 | `@ConfigurationProperties`不仅可以注解在类上,也可以注解在public `@Bean`方法上,当你需要为不受控的第三方组件绑定属性时,该方法将非常有用。
4 |
5 | 为了从`Environment`属性中配置一个bean,你需要使用`@ConfigurationProperties`注解该bean:
6 | ```java
7 | @ConfigurationProperties(prefix = "foo")
8 | @Bean
9 | public FooComponent fooComponent() {
10 | ...
11 | }
12 | ```
13 | 和上面`ConnectionSettings`的示例方式相同,所有以`foo`为前缀的属性定义都会被映射到`FooComponent`上。
14 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/35. Distributed Transactions with JTA.md:
--------------------------------------------------------------------------------
1 | ### 35. 使用JTA处理分布式事务
2 |
3 | Spring Boot通过[Atomkos](http://www.atomikos.com/)或[Bitronix](http://docs.codehaus.org/display/BTM/Home)的内嵌事务管理器支持跨多个XA资源的分布式JTA事务,当部署到恰当的J2EE应用服务器时也会支持JTA事务。
4 |
5 | 当发现JTA环境时,Spring Boot将使用Spring的`JtaTransactionManager`来管理事务。自动配置的JMS,DataSource和JPA beans将被升级以支持XA事务。你可以使用标准的Spring idioms,比如`@Transactional`,来参与到一个分布式事务中。如果处于JTA环境,但仍想使用本地事务,你可以将`spring.jta.enabled`属性设置为`false`来禁用JTA自动配置功能。
6 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/35.4 Using a Java EE managed transaction manager.md:
--------------------------------------------------------------------------------
1 | ###35.4 使用J2EE管理的事务管理器
2 |
3 | 如果你将Spring Boot应用打包为一个`war`或`ear`文件,并将它部署到一个J2EE的应用服务器中,那你就能使用应用服务器内建的事务管理器。Spring Boot将尝试通过查找常见的JNDI路径(`java:comp/UserTransaction`, `java:comp/TransactionManager`等)来自动配置一个事务管理器。如果使用应用服务器提供的事务服务,你通常需要确保所有的资源都被应用服务器管理,并通过JNDI暴露出去。Spring Boot通过查找JNDI路径`java:/JmsXA`或`java:/XAConnectionFactory`获取一个`ConnectionFactory`来自动配置JMS,并且你可以使用`spring.datasource.jndi-name`属性配置你的`DataSource`。
4 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/40.3.5 Auto-configured tests.md:
--------------------------------------------------------------------------------
1 | ###40.3.5 自动配置测试
2 | Spring Boot的自动配置系统对应用来说很合适,但用于测试就有点杀鸡用牛刀了,测试时只加载需要的应用片段(slice)通常是有好处的。例如,你可能想测试Spring MVC控制器映射URLs是否正确,且不想在这些测试中涉及到数据库调用;或者你想测试JPA实体,那测试运行时你可能对web层不感兴趣。
3 |
4 | `spring-boot-test-autoconfigure`模块包含很多用来自动配置这些片段(slices)的注解,每个工作方式都相似,都是提供一个`@…Test`注解,然后加载`ApplicationContext`,使用一个或多个`@AutoConfigure…`注解自定义设置。
5 |
6 | **注** `@AutoConfigure…`注解也可以跟标准的`@SpringBootTest`注解一块使用,如果对应用片段不感兴趣,只是想获取自动配置的一些测试beans,你可以使用该组合。
7 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/23.10 Admin features.md:
--------------------------------------------------------------------------------
1 | ### 23.10 Admin特性
2 |
3 | 通过设置`spring.application.admin.enabled`属性可以启用管理相关的(admin-related)特性,这将暴露[SpringApplicationAdminMXBean](https://github.com/spring-projects/spring-boot/tree/v1.4.1.RELEASE/spring-boot/src/main/java/org/springframework/boot/admin/SpringApplicationAdminMXBean.java)到平台的`MBeanServer`,你可以使用该特性远程管理Spring Boot应用,这对任何service包装器(wrapper)实现也有用。
4 |
5 | **注** 通过`local.server.port`可以获取该应用运行的HTTP端口。启用该特性时需要注意MBean会暴露一个方法去关闭应用。
6 |
7 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/70.20 Enable HTTP response compression.md:
--------------------------------------------------------------------------------
1 | ### 70.20 启用HTTP响应压缩
2 |
3 | Jetty,Tomcat和Undertow支持HTTP响应压缩,你可以通过设置`server.compression.enabled`启用它:
4 | ```properties
5 | server.compression.enabled=true
6 | ```
7 | 默认情况下,响应信息长度至少2048字节才能触发压缩,通过`server.compression.min-response-size`属性可以改变该长度。另外,只有响应的content type为以下其中之一时才压缩:
8 |
9 | - `text/html`
10 | - `text/xml`
11 | - `text/plain`
12 | - `text/css`
13 |
14 | 你可以通过`server.compression.mime-types`属性配置。
15 |
--------------------------------------------------------------------------------
/VII. Spring Boot CLI/62. What to read next.md:
--------------------------------------------------------------------------------
1 | ### 62. 接下来阅读什么
2 | GitHub仓库有一些[groovy脚本示例](https://github.com/spring-projects/spring-boot/tree/v1.4.1.RELEASE/spring-boot-cli/samples)可用于尝试Spring Boot CLI,[源码](https://github.com/spring-projects/spring-boot/tree/v1.4.1.RELEASE/spring-boot-cli/src/main/java/org/springframework/boot/cli)里也有丰富的文档说明。
3 |
4 | 如果发现已触及CLI工具的限制,你可以将应用完全转换为Gradle或Maven构建的groovy工程。下一章节将覆盖Spring Boot的[构建工具](../VIII. Build tool plugins/README.md),这些工具可以跟Gradle或Maven一起使用。
5 |
--------------------------------------------------------------------------------
/III. Using Spring Boot/20.2.1 Excluding resources.md:
--------------------------------------------------------------------------------
1 | ###20.2.1 排除资源
2 |
3 | 某些资源的变化没必要触发重启,比如Thymeleaf模板可以随时编辑。默认情况下,位于`/META-INF/maven`,`/META-INF/resources`,`/resources`,`/static`,`/public`或`/templates`下的资源变更不会触发重启,但会触发实时加载(live reload)。你可以使用`spring.devtools.restart.exclude`属性自定义这些排除规则,比如,为了只排除`/static`和`/public`,你可以这样设置:
4 | ```properties
5 | spring.devtools.restart.exclude=static/**,public/**
6 | ```
7 |
8 | **注** 如果你想保留默认属性,并添加其他的排除规则,可以使用`spring.devtools.restart.additional-exclude`属性作为代替。
9 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/28.4 Actuator Security.md:
--------------------------------------------------------------------------------
1 | ### 28.4 Actuator安全
2 | 如果Actuator处于使用中,你会发现:
3 |
4 | * 管理的端点是安全的,即使应用端点不安全。
5 | * Security事件转换为`AuditEvents`,并发布到`AuditService`。
6 | * 默认用户有`ADMIN`,`USER`角色。
7 |
8 | Actuator的安全特性可以通过外部配置属性(`management.security.*`)进行修改。为了覆盖应用访问规则但不覆盖actuator的访问规则,你可以添加一个`WebSecurityConfigurerAdapter`类型的`@Bean`,并注解`@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)`,如果想覆盖actuator访问规则,则注解`@Order(ManagementServerProperties.ACCESS_OVERRIDE_ORDER)`。
9 |
10 |
11 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/70.17.2 Use Jetty 9.2 with Gradle.md:
--------------------------------------------------------------------------------
1 | ### 70.17.2 通过Gradle使用Jetty 9.2
2 |
3 | 对于Gradle,你需要设置`jetty.version`属性,例如对于一个简单的webapp或service:
4 | ```gradle
5 | ext['jetty.version'] = '9.2.17.v20160517'
6 | dependencies {
7 | compile ('org.springframework.boot:spring-boot-starter-web') {
8 | exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
9 | }
10 | compile ('org.springframework.boot:spring-boot-starter-jetty')
11 | }
12 | ```
13 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/31.1.4 Hazelcast.md:
--------------------------------------------------------------------------------
1 | ###31.1.4 Hazelcast
2 | Spring Boot为Hazelcast提供[通常的支持](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/htmlsingle/#boot-features-hazelcast),如果`HazelcastInstance`被自动配置,那它将自动包装进一个`CacheManager`。
3 |
4 | 如果出于某些原因,需要使用另一个不同的`HazelcastInstance`,你可以请求Spring Boot创建一个单独的实例,并只用于该`CacheManager`:
5 | ```properties
6 | spring.cache.hazelcast.config=classpath:config/my-cache-hazelcast.xml
7 | ```
8 | **注** 如果以这种方式创建一个单独的`HazelcastInstance`,它将不会注册到应用上下文中。
9 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/70.14 Configure Undertow.md:
--------------------------------------------------------------------------------
1 | ### 70.14 配置Undertow
2 |
3 | 通常你可以遵循[Section 69.8, “Discover built-in options for external properties”](./69.8 Discover built-in options for external properties.md)关于`@ConfigurationProperties`(此处主要是`ServerProperties`和`ServerProperties.Undertow`),但也要看下`EmbeddedServletContainerCustomizer`。
4 |
5 | 一旦获取到`UndertowEmbeddedServletContainerFactory`,你就可以使用`UndertowBuilderCustomizer`修改Undertow的配置以满足你的需求,或更彻底地就是添加你自己的`UndertowEmbeddedServletContainerFactory`。
6 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/50.7 Special features with Java 8.md:
--------------------------------------------------------------------------------
1 | ### 50.7 使用Java8的特性
2 | Spring Boot提供的`GaugeService`和`CounterService`默认实现依赖于你使用的Java版本。如果使用Java8(或更高版本),Spring Boot将实现切换为一个高性能版本,该版本优化了写速度,底层使用原子内存buffers,而不是通过不可变但相对昂贵的`Metric>`类型(跟基于仓库的实现相比,counters大概快5倍,gauges大概快2倍)。对于Java7,Dropwizard指标服务也是很有效的(使用了某些Java8并发库),但它不记录指标值的时间戳。如果需要关注指标采集的性能,建议你使用高性能的选项,并不要频繁读取指标信息,这样写入会本地缓存,只有在需要时读取。
3 |
4 | **注** 如果使用Java8或Dropwizard,Spring Boot默认不会使用老的`MetricRepository`和它的`InMemoryMetricRepository`实现。
5 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/54. What to read next.md:
--------------------------------------------------------------------------------
1 | ### 54. 接下来阅读什么
2 | 如果想探索本章节讨论的某些内容,你可以看下执行器的[示例应用](https://github.com/spring-projects/spring-boot/tree/v1.4.1.RELEASE/spring-boot-samples),你也可能想了解图形工具比如[Graphite](http://graphite.wikidot.com/)。
3 |
4 | 此外,你可以继续了解[‘deployment options’](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/htmlsingle/#deployment)或直接跳到Spring Boot的[build tool plugins](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/htmlsingle/#build-tool-plugins)。
5 |
--------------------------------------------------------------------------------
/II. Getting started/8. Introducing Spring Boot.md:
--------------------------------------------------------------------------------
1 | ### 8. Spring Boot介绍
2 |
3 | Spring Boot简化了基于Spring的应用开发,你只需要"run"就能创建一个独立的,产品级别的Spring应用。
4 | 我们为Spring平台及第三方库提供开箱即用的设置,这样你就可以有条不紊地开始。多数Spring Boot应用只需要很少的Spring配置。
5 |
6 | 你可以使用Spring Boot创建Java应用,并使用`java -jar`启动它或采用传统的war部署方式。我们也提供了一个运行"spring脚本"的命令行工具。
7 |
8 | 我们主要的目标是:
9 |
10 | - 为所有Spring开发提供一个从根本上更快,且随处可得的入门体验。
11 | - 开箱即用,但通过不采用默认设置可以快速摆脱这种方式。
12 | - 提供一系列大型项目常用的非功能性特征,比如:内嵌服务器,安全,指标,健康检测,外部化配置。
13 | - 绝对没有代码生成,也不需要XML配置。
14 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/23.6. Web environment.md:
--------------------------------------------------------------------------------
1 | ### 23.6. Web环境
2 |
3 | `SpringApplication`将尝试为你创建正确类型的`ApplicationContext`,默认情况下,根据你开发的是否为web应用决定使用`AnnotationConfigApplicationContext`或`AnnotationConfigEmbeddedWebApplicationContext`。
4 |
5 | 用于确定是否为web环境的算法相当简单(判断是否存在某些类),你可以使用`setWebEnvironment(boolean webEnvironment)`覆盖默认行为。
6 |
7 | 通过调用`setApplicationContextClass(…)`,你可以完全控制`ApplicationContext`的类型。
8 |
9 | **注** 在Junit测试中使用`SpringApplication`,调用`setWebEnvironment(false)`是很有意义的。
10 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/24.1. Configuring random values.md:
--------------------------------------------------------------------------------
1 | ### 24.1. 配置随机值
2 |
3 | 在注入随机值(比如,密钥或测试用例)时`RandomValuePropertySource`很有用,它能产生整数,longs或字符串,比如:
4 | ```java
5 | my.secret=${random.value}
6 | my.number=${random.int}
7 | my.bignumber=${random.long}
8 | my.number.less.than.ten=${random.int(10)}
9 | my.number.in.range=${random.int[1024,65536]}
10 | ```
11 | `random.int*`语法是`OPEN value (,max) CLOSE`,此处`OPEN,CLOSE`可以是任何字符,并且`value,max`是整数。如果提供`max`,那么`value`是最小值,`max`是最大值(不包含在内)。
12 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/44. What to read next.md:
--------------------------------------------------------------------------------
1 | ### 44. 接下来阅读什么
2 | 如果想了解本章节讨论类的更多内容,你可以查看[Spring Boot API文档](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/api),或直接浏览[源码](https://github.com/spring-projects/spring-boot/tree/v1.4.1.RELEASE)。如果有特别问题,可以参考[how-to](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/htmlsingle/#howto)章节。
3 |
4 | 如果已熟悉Spring Boot的核心特性,你可以继续并查看[production-ready特性](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/htmlsingle/#production-ready)。
5 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/46.4 Adding custom endpoints.md:
--------------------------------------------------------------------------------
1 | ###46.4 添加自定义端点
2 | 如果添加一个`Endpoint`类型的`@Bean`,Spring Boot会自动通过JMX和HTTP(如果有可用服务器)将该端点暴露出去。通过创建`MvcEndpoint`类型的bean可进一步定义HTTP端点,虽然该bean不是`@Controller`,但仍能使用`@RequestMapping`(和`@Managed*`)暴露资源。
3 |
4 | **注** 如果你的用户需要一个单独的管理端口或地址,你可以将注解`@ManagementContextConfiguration`的配置类添加到`/META-INF/spring.factories`中,且key为`org.springframework.boot.actuate.autoconfigure.ManagementContextConfiguration`,这样该端点将跟其他MVC端点一样移动到一个子上下文中,通过`WebConfigurerAdapter`可以为管理端点添加静态资源。
5 |
--------------------------------------------------------------------------------
/III. Using Spring Boot/19.5. Hot swapping.md:
--------------------------------------------------------------------------------
1 | ### 19.5. 热交换
2 |
3 | 由于Spring Boot应用只是普通的Java应用,所以JVM热交换(hot-swapping)也能开箱即用。不过JVM热交换能替换的字节码有限制,想要更彻底的解决方案可以使用[Spring Loaded](https://github.com/spring-projects/spring-loaded)项目或[JRebel](http://zeroturnaround.com/software/jrebel/)。`spring-boot-devtools`模块也支持应用快速重启(restart)。
4 |
5 | 详情参考下面的[Chapter 20, Developer tools](http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#using-boot-devtools)和[“How-to”](../IX. ‘How-to’ guides/README.md)章节。
6 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/70.19 Create WebSocket endpoints using @ServerEndpoint.md:
--------------------------------------------------------------------------------
1 | ### 70.19 使用@ServerEndpoint创建WebSocket端点
2 |
3 | 如果想在使用内嵌容器的Spring Boot应用中使用`@ServerEndpoint`,你需要声明一个单独的`ServerEndpointExporter` `@Bean`:
4 | ```java
5 | @Bean
6 | public ServerEndpointExporter serverEndpointExporter() {
7 | return new ServerEndpointExporter();
8 | }
9 | ```
10 | 该bean将使用底层的WebSocket容器注册任何被`@ServerEndpoint`注解的beans。当部署到一个单独的servlet容器时,该角色将被一个servlet容器初始化方法执行,`ServerEndpointExporter` bean也就不需要了。
11 |
--------------------------------------------------------------------------------
/VII. Spring Boot CLI/59.6 Using the embedded shell.md:
--------------------------------------------------------------------------------
1 | ### 59.6 使用内嵌shell
2 | Spring Boot包括完整的BASH和zsh shells的命令行脚本,如果这两种你都不使用(可能你是一个Window用户),那你可以使用`shell`命令启用一个集成shell。
3 | ```shell
4 | $ spring shell
5 | Spring Boot (v1.4.1.RELEASE)
6 | Hit TAB to complete. Type \'help' and hit RETURN for help, and \'exit' to quit.
7 | ```
8 | 从内嵌shell中可以直接运行其他命令:
9 | ```shell
10 | $ version
11 | Spring CLI v1.4.1.RELEASE
12 | ```
13 | 内嵌shell支持ANSI彩色输出和tab补全,如果需要运行一个原生命令,你可以使用`!`前缀,点击`ctrl-c`将退出内嵌shell。
14 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/69.1.2. Automatic property expansion using Gradle.md:
--------------------------------------------------------------------------------
1 | ###69.1.2. 使用Gradle自动暴露属性
2 |
3 | 你可以通过配置Java插件的`processResources`任务自动暴露来自Gradle项目的属性:
4 | ```gradle
5 | processResources {
6 | expand(project.properties)
7 | }
8 | ```
9 | 然后你可以通过占位符引用Gradle项目的属性:
10 | ```properties
11 | app.name=${name}
12 | app.description=${description}
13 | ```
14 |
15 | **注** Gradle的`expand`方法使用Groovy的`SimpleTemplateEngine`转换`${..}`占位符,`${..}`这种格式跟Spring自身的属性占位符机制冲突,想要自动暴露Spring属性占位符,你需要将其进行编码,比如`\${..}`。
16 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/26.2. Console output.md:
--------------------------------------------------------------------------------
1 | ### 26.2. 控制台输出
2 |
3 | 默认的日志配置会在写日志消息时将它们回显到控制台,级别为`ERROR`, `WARN`和`INFO`的消息会被记录。你可以在启动应用时,通过`--debug`标识开启控制台的`DEBUG`级别日志记录,也可以在`application.properties`中指定`debug=true`。
4 | ```shell
5 | $ java -jar myapp.jar --debug
6 | ```
7 | 当debug模式启用时,一系列核心loggers(内嵌容器,Hibernate,Spring Boot等)记录的日志会变多,但不会输出所有的信息。
8 |
9 | 相应地,你可以在启动应用时,通过`--trace`(或在`application.properties`设置`trace=true`)启用"trace"模式,该模式能够追踪核心loggers(内嵌容器,Hibernate生成的schema,Spring全部的portfolio)的所有日志信息。
10 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/30.3.4 Spring Data Neo4j repositories.md:
--------------------------------------------------------------------------------
1 | ### 30.3.4 Spring Data Neo4j仓库
2 | Spring Data包含的仓库也支持Neo4j,实际上,Spring Data JPA和Spring Data Neo4j使用相同的常用设施,所以你可以采用先前JPA的示例,假设`City`现在是一个Neo4j OGM `@NodeEntity`而不是JPA `@Entity`,它将以同样的方式工作。
3 |
4 | **注** 你可以使用`@EntityScan`注解定义实体扫描路径。
5 |
6 | 将以下两个注解添加到你的Spring configuration,可以启用repository支持(还有可选的对`@Transactional`的支持):
7 | ```java
8 | @EnableNeo4jRepositories(basePackages = "com.example.myapp.repository")
9 | @EnableTransactionManagement
10 | ```
11 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/30.4 Gemfire.md:
--------------------------------------------------------------------------------
1 | ### 30.4 Gemfire
2 |
3 | [Spring Data Gemfire](https://github.com/spring-projects/spring-data-gemfire)为使用[Pivotal Gemfire](http://www.pivotal.io/big-data/pivotal-gemfire#details)数据管理平台提供了方便的,Spring友好的工具。Spring Boot提供了一个用于聚集依赖的`spring-boot-starter-data-gemfire`'Starter',目前不支持Gemfire的自动配置,但你只需使用[一个注解](https://github.com/spring-projects/spring-data-gemfire/blob/master/src/main/java/org/springframework/data/gemfire/repository/config/EnableGemfireRepositories.java)就能使Spring Data仓库支持它。
4 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/37. Spring Integration.md:
--------------------------------------------------------------------------------
1 | ###37. Spring集成
2 | Spring Boot为Spring集成提供了一些便利,包括`spring-boot-starter-integration` ‘Starter’。
3 | Spring集成提供基于消息和其他传输协议的抽象,比如HTTP,TCP等。如果添加Spring集成依赖,使用`@EnableIntegration`注解可以初始化它。如果classpath下存在'spring-integration-jmx'依赖,则消息处理统计分析将被通过JMX发布出去,具体参考[IntegrationAutoConfiguration类](https://github.com/spring-projects/spring-boot/tree/v1.4.1.RELEASE/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java)。
4 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/50.1 System metrics.md:
--------------------------------------------------------------------------------
1 | ### 50.1 系统指标
2 | Spring Boot会暴露以下系统指标:
3 | - 系统内存总量(`mem`),单位:KB
4 | - 空闲内存数量(`mem.free`),单位:KB
5 | - 处理器数量(`processors`)
6 | - 系统正常运行时间(`uptime`),单位:毫秒
7 | - 应用上下文(应用实例)正常运行时间(`instance.uptime`),单位:毫秒
8 | - 系统平均负载(`systemload.average`)
9 | - 堆信息(`heap`,`heap.committed`,`heap.init`,`heap.used`),单位:KB
10 | - 线程信息(`threads`,`thread.peak`,`thead.daemon`)
11 | - 类加载信息(`classes`,`classes.loaded`,`classes.unloaded`)
12 | - 垃圾收集信息(`gc.xxx.count`, `gc.xxx.time`)
13 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/43.1 Understanding auto-configured beans.md:
--------------------------------------------------------------------------------
1 | ###43.1 理解自动配置的beans
2 | 从底层来讲,自动配置(auto-configuration)是通过标准的`@Configuration`类实现的。此外,`@Conditional`注解用来约束自动配置生效的条件。通常自动配置类需要使用`@ConditionalOnClass`和`@ConditionalOnMissingBean`注解,这是为了确保只有在相关的类被发现及没有声明自定义的`@Configuration`时才应用自动配置,具体查看[`spring-boot-autoconfigure`](https://github.com/spring-projects/spring-boot/tree/v1.4.1.RELEASE/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure)源码中的`@Configuration`类(`META-INF/spring.factories`文件)。
3 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/49. Monitoring and management using a remote shell.md:
--------------------------------------------------------------------------------
1 | ### 49. 使用远程shell进行监控和管理
2 | Spring Boot支持集成一个称为'CRaSH'的Java shell,你可以在CRaSH中使用ssh或telnet命令连接到运行的应用,项目中添加以下依赖可以启用远程shell支持:
3 | ```xml
4 |
5 | org.springframework.boot
6 | spring-boot-starter-remote-shell
7 |
8 | ```
9 | **注** 如果想使用telnet访问,你还需添加对`org.crsh:crsh.shell.telnet`的依赖。
10 |
11 | **注** CRaSH运行时需要JDK,因为它要动态编译命令。如果一个基本的`help`命令都运行失败,你很可能使用的是JRE。
12 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/27.3.3 The EmbeddedWebApplicationContext.md:
--------------------------------------------------------------------------------
1 | ### 27.3.3 EmbeddedWebApplicationContext
2 |
3 | Spring Boot底层使用一种新的`ApplicationContext`类型,用于对内嵌servlet容器的支持。`EmbeddedWebApplicationContext`是一种特殊类型的`WebApplicationContext`,它通过搜索到的单个`EmbeddedServletContainerFactory` bean来启动自己,通常`TomcatEmbeddedServletContainerFactory`,`JettyEmbeddedServletContainerFactory`或`UndertowEmbeddedServletContainerFactory`将被自动配置。
4 |
5 | **注** 你不需要关心这些实现类,大部分应用都能被自动配置,并根据你的行为创建合适的`ApplicationContext`和`EmbeddedServletContainerFactory`。
6 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/43.3.2 Bean conditions.md:
--------------------------------------------------------------------------------
1 | ###43.3.2 Bean条件
2 | `@ConditionalOnBean`和`@ConditionalOnMissingBean`注解可以根据特定类是否存在决定bean的包含,你可以使用`value`属性指定beans(by type),也可以使用`name`定义beans(by name),`search`属性用于限制搜索beans时需要考虑的`ApplicationContext`层次。
3 |
4 | **注** 你需要注意bean定义添加的顺序,因为这些条件的计算是基于目前处理内容的。出于这个原因,我们推荐在自动配置类上只使用`@ConditionalOnBean`和`@ConditionalOnMissingBean`注解(即使保证它们在其他用户定义的beans后加载)。
5 |
6 | **注** `@ConditionalOnBean`和`@ConditionalOnMissingBean`不会阻止`@Configuration`类的创建,在类级别使用那些conditions跟使用注解标记每个`@Bean`方法是等价的。
7 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/75.2 Initialize a database using Hibernate.md:
--------------------------------------------------------------------------------
1 | ### 75.2 使用Hibernate初始化数据库
2 |
3 | 你可以显式设置`spring.jpa.hibernate.ddl-auto`,标准的Hibernate属性值有`none`,`validate`,`update`,`create`,`create-drop`。Spring Boot根据你的数据库是否为内嵌数据库来选择相应的默认值,如果是内嵌型的则默认值为`create-drop`,否则为`none`。通过查看`Connection`类型可以检查是否为内嵌型数据库,hsqldb,h2和derby是内嵌的,其他都不是。当从内存数据库迁移到一个真正的数据库时,你需要当心,在新的平台中不能对数据库表和数据是否存在进行臆断,你也需要显式设置`ddl-auto`,或使用其他机制初始化数据库。
4 |
5 | 此外,启动时处于classpath根目录下的`import.sql`文件会被执行。这在demos或测试时很有用,但在生产环境中你可能不期望这样。这是Hibernate的特性,和Spring没有一点关系。
6 |
--------------------------------------------------------------------------------
/X. Appendices/B.2.1. Nested properties.md:
--------------------------------------------------------------------------------
1 | ### 附录 B.2.1. 内嵌属性
2 |
3 | 该注解处理器自动将内部类当做内嵌属性处理。例如,下面的类:
4 | ```java
5 | @ConfigurationProperties(prefix="server")
6 | public class ServerProperties {
7 |
8 | private String name;
9 |
10 | private Host host;
11 |
12 | // ... getter and setters
13 |
14 | private static class Host {
15 |
16 | private String ip;
17 |
18 | private int port;
19 |
20 | // ... getter and setters
21 |
22 | }
23 |
24 | }
25 | ```
26 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/74.9 Use Spring Data JPA and Mongo repositories.md:
--------------------------------------------------------------------------------
1 | ### 74.9 使用Spring Data JPA和Mongo仓库
2 |
3 | Spring Data JPA和Spring Data Mongo都能自动为你创建`Repository`实现。如果它们同时出现在classpath下,你可能需要添加额外的配置来告诉Spring Boot你想要哪个(或两个)为你创建仓库。最明确地方式是使用标准的Spring Data `@Enable*Repositories`,然后告诉它你的`Repository`接口的位置(此处`*`即可以是Jpa,也可以是Mongo,或者两者都是)。
4 |
5 | 这里也有`spring.data.*.repositories.enabled`标志,可用来在外部配置中开启或关闭仓库的自动配置,这在你想关闭Mongo仓库但仍使用自动配置的`MongoTemplate`时非常有用。
6 |
7 | 相同的障碍和特性也存在于其他自动配置的Spring Data仓库类型(Elasticsearch, Solr),只需要改变对应注解的名称和标志。
8 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/47.3 Customizing the management server port.md:
--------------------------------------------------------------------------------
1 | ### 47.3 自定义管理服务器端口
2 | 对于基于云的部署,使用默认的HTTP端口暴露管理端点(endpoints)是明智的选择。然而,如果你的应用是在自己的数据中心运行,那你可能倾向于使用一个不同的HTTP端口来暴露端点。`management.port`属性可以用来改变HTTP端口:
3 | ```java
4 | management.port=8081
5 | ```
6 | 由于你的管理端口经常被防火墙保护,不对外暴露也就不需要保护管理端点,即使你的主应用是受保护的。在这种情况下,classpath下会存在Spring Security库,你可以设置以下属性来禁用安全管理策略(management security):
7 | ```java
8 | management.security.enabled=false
9 | ```
10 | (如果classpath下不存在Spring Security,那也就不需要显式的以这种方式来禁用安全管理策略,它甚至可能会破坏应用程序。)
11 |
--------------------------------------------------------------------------------
/VI. Deploying Spring Boot applications/55. Deploying to the cloud.md:
--------------------------------------------------------------------------------
1 | ###55. 部署到云端
2 | 对于大多数流行云PaaS(平台即服务)提供商,Spring Boot的可执行jars就是为它们准备的。这些提供商往往要求你自己提供容器,它们只负责管理应用的进程(不特别针对Java应用程序),所以它们需要一些中间层来将你的应用适配到云概念中的一个运行进程。
3 |
4 | 两个流行的云提供商,Heroku和Cloud Foundry,采取一个打包('buildpack')方法。为了启动你的应用程序,不管需要什么,buildpack都会将它们打包到你的部署代码:它可能是一个JDK和一个java调用,也可能是一个内嵌的webserver,或者是一个成熟的应用服务器。buildpack是可插拔的,但你最好尽可能少的对它进行自定义设置。这可以减少不受你控制的功能范围,最小化部署和生产环境的发散。
5 |
6 | 理想情况下,你的应用就像一个Spring Boot可执行jar,所有运行需要的东西都打包到它内部。
7 |
8 | 本章节我们将看到在“Getting Started”章节开发的简单应用是怎么在云端运行的。
9 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/49.1.1 Remote shell credentials.md:
--------------------------------------------------------------------------------
1 | ### 49.1.1 远程shell证书
2 | 你可以使用`management.shell.auth.simple.user.name`和`management.shell.auth.simple.user.password`属性配置自定义的连接证书,也可以使用Spring Security的`AuthenticationManager`处理登录职责,具体参考[CrshAutoConfiguration](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/api/org/springframework/boot/actuate/autoconfigure/CrshAutoConfiguration.html)和[ShellProperties](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/api/org/springframework/boot/actuate/autoconfigure/ShellProperties.html)的Javadoc。
3 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/27.3.5 JSP limitations.md:
--------------------------------------------------------------------------------
1 | ### 27.3.5 JSP的限制
2 |
3 | 当使用内嵌servlet容器运行Spring Boot应用时(并打包成一个可执行的存档archive),容器对JSP的支持有一些限制:
4 |
5 | 1. Tomcat只支持war的打包方式,不支持可执行jar。
6 | 2. Jetty只支持war的打包方式。
7 | 3. Undertow不支持JSPs。
8 | 4. 创建的自定义`error.jsp`页面不会覆盖默认的[error handling](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/htmlsingle/#boot-features-error-handling)视图。
9 |
10 | 这里有个[JSP示例](http://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-web-jsp),你可以查看如何设置相关事项。
11 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/30.3.5 Repository example.md:
--------------------------------------------------------------------------------
1 | ### 30.3.5 仓库示例
2 | ```java
3 | package com.example.myapp.domain;
4 |
5 | import org.springframework.data.domain.*;
6 | import org.springframework.data.repository.*;
7 |
8 | public interface CityRepository extends GraphRepository {
9 |
10 | Page findAll(Pageable pageable);
11 |
12 | City findByNameAndCountry(String name, String country);
13 |
14 | }
15 | ```
16 | **注** 想详细了解Spring Data Neo4j,包括它丰富的对象映射技术,可查看它的[参考文档](http://projects.spring.io/spring-data-neo4j/)。
17 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/40.2 Testing Spring applications.md:
--------------------------------------------------------------------------------
1 | ###40.2 测试Spring应用
2 |
3 | 依赖注入主要优势之一就是它能够让你的代码更容易进行单元测试。你只需简单的通过`new`操作符实例化对象,甚至不需要涉及Spring,也可以使用模拟对象替换真正的依赖。
4 |
5 | 你常常需要在进行单元测试后,开始集成测试(在这个过程中只需要涉及到Spring的`ApplicationContext`)。在执行集成测试时,不需要部署应用或连接到其他基础设施是非常有用的,Spring框架为实现这样的集成测试提供了一个专用的测试模块,通过声明`org.springframework:spring-test`的依赖,或使用`spring-boot-starter-test` ‘Starter’就可以使用它了。
6 |
7 | 如果以前没有使用过`spring-test`模块,可以查看Spring框架参考文档中的[相关章节](http://docs.spring.io/spring/docs/4.3.3.RELEASE/spring-framework-reference/htmlsingle/#testing)。
8 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/71.1 Write a JSON REST service.md:
--------------------------------------------------------------------------------
1 | ### 71.1 编写JSON REST服务
2 |
3 | 只要添加的有Jackson2依赖,Spring Boot应用中的任何`@RestController`默认都会渲染为JSON响应,例如:
4 | ```java
5 | @RestController
6 | public class MyController {
7 |
8 | @RequestMapping("/thing")
9 | public MyThing thing() {
10 | return new MyThing();
11 | }
12 |
13 | }
14 | ```
15 | 只要`MyThing`能够通过Jackson2序列化(比如,一个标准的POJO或Groovy对象),默认[localhost:8080/thing](http://localhost:8080/thing)将响应一个JSON数据。有时在浏览器中你可能看到XML响应,因为浏览器倾向于发送XML accept headers。
16 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/46.5 Health information.md:
--------------------------------------------------------------------------------
1 | ### 46.5 健康信息
2 | 健康信息可以检查应用的运行状态,它经常被监控软件用来提醒人们生产环境是否存在问题。`health`端点暴露的默认信息取决于端点是如何被访问的。对于一个非安全,未认证的连接只返回一个简单的'status'信息。对于一个安全或认证过的连接其他详细信息也会展示(具体参考[章节47.7, “HTTP健康端点访问限制” ](47.7. HTTP Health endpoint access restrictions.md))。
3 |
4 | 健康信息是从你的`ApplicationContext`中定义的所有[HealthIndicator](http://github.com/spring-projects/spring-boot/tree/master/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthIndicator.java) beans收集过来的。Spring Boot包含很多自动配置的`HealthIndicators`,你也可以写自己的。
5 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/29.4 Using H2’s web console.md:
--------------------------------------------------------------------------------
1 | ### 29.4 使用H2的web控制台
2 | [H2数据库](http://www.h2database.com/)提供一个[基于浏览器的控制台](http://www.h2database.com/html/quickstart.html#h2_console),Spring Boot可以为你自动配置。如果以下条件满足,则控制台会被自动配置:
3 |
4 | * 你正在开发一个web应用。
5 | * 添加`com.h2database:h2`依赖。
6 | * 你正在使用[Spring Boot开发者工具](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/htmlsingle/#using-boot-devtools)。
7 |
8 | **注** 如果你没有使用Spring Boot的开发者工具,仍想利用H2的控制台,可以设置`spring.h2.console.enabled`属性值为`true`。H2控制台应该只用于开发期间,所以确保生产环境没有设置`spring.h2.console.enabled`。
9 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/43. Creating your own auto-configuration.md:
--------------------------------------------------------------------------------
1 | ###43. 创建自己的auto-configuration
2 | 如果你在公司里开发共享libraries,或者正在开发一个开源或商业library,你可能想开发自己的自动配置(auto-configuration)。自动配置类可以打包到外部jars,并且依旧可以被Spring Boot识别。自动配置可以关联一个"starter",用于提供auto-configuration的代码及需要引用的libraries。我们首先讲解构建自己的auto-configuration需要知道哪些内容,然后讲解[创建自定义starter的常见步骤](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/htmlsingle/#boot-features-custom-starter)。
3 |
4 | **注** 可参考[demo工程](https://github.com/snicoll-demos/spring-boot-master-auto-configuration)了解如何一步步创建一个starter。
5 |
--------------------------------------------------------------------------------
/VI. Deploying Spring Boot applications/57. What to read next.md:
--------------------------------------------------------------------------------
1 | ###57. 接下来阅读什么
2 | 打开[Cloud Foundry](http://www.cloudfoundry.com/),[Heroku](https://www.heroku.com/),[OpenShift](https://www.openshift.com/)和[Boxfuse](https://boxfuse.com/)网站获取更多Paas能提供的特性信息。这里只提到4个比较流行的Java PaaS提供商,由于Spring Boot遵从基于云的部署原则,所以你也可以自由考虑其他提供商。
3 |
4 | 下章节将继续讲解[Spring Boot CLI](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/htmlsingle/#cli),你也可以直接跳到[build tool plugins](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/htmlsingle/#build-tool-plugins)。
5 |
--------------------------------------------------------------------------------
/X. Appendices/D.1.1. The executable jar file structure.md:
--------------------------------------------------------------------------------
1 | ### 附录D.1.1 可执行jar文件结构
2 |
3 | Spring Boot Loader兼容的jar文件应该遵循以下结构:
4 |
5 | ```java
6 | example.jar
7 | |
8 | +-META-INF
9 | | +-MANIFEST.MF
10 | +-org
11 | | +-springframework
12 | | +-boot
13 | | +-loader
14 | | +-
15 | +-com
16 | | +-mycompany
17 | | + project
18 | | +-YouClasses.class
19 | +-lib
20 | +-dependency1.jar
21 | +-dependency2.jar
22 | ```
23 | 依赖需要放到内部的lib目录下。
24 |
25 |
--------------------------------------------------------------------------------
/X. Appendices/D.3. Launching executable jars.md:
--------------------------------------------------------------------------------
1 | ### 附录D.3. 启动可执行jars
2 |
3 | `org.springframework.boot.loader.Launcher`类是个特殊的启动类,用于一个可执行jars的主要入口。它实际上就是你jar文件的`Main-Class`,并用来设置一个合适的`URLClassLoader`,最后调用你的`main()`方法。
4 |
5 | 这里有3个启动器子类,JarLauncher,WarLauncher和PropertiesLauncher。它们的作用是从嵌套的jar或war文件目录中(相对于显示的从classpath)加载资源(.class文件等)。在`[Jar|War]Launcher`情况下,嵌套路径是固定的(`lib/*.jar`和war的`lib-provided/*.jar`),所以如果你需要很多其他jars只需添加到那些位置即可。PropertiesLauncher默认查找你应用存档的`lib/`目录,但你可以通过设置环境变量`LOADER_PATH`或application.properties中的`loader.path`来添加其他的位置(逗号分割的目录或存档列表)。
6 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/30.2.4 Embedded Mongo.md:
--------------------------------------------------------------------------------
1 | ### 30.2.4 内嵌的Mongo
2 | Spring Boot为[内嵌Mongo](https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo)提供自动配置,你需要添加`de.flapdoodle.embed:de.flapdoodle.embed.mongo`依赖才能使用它。
3 |
4 | `spring.data.mongodb.port`属性可用来配置Mongo监听的端口,将该属性值设为0,表示使用一个随机分配的可用端口。通过`MongoAutoConfiguration`创建的`MongoClient`将自动配置为使用随机分配的端口。
5 |
6 | 如果classpath下存在SLF4J依赖,Mongo产生的输出将自动路由到一个名为`org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongo`的logger。
7 |
8 | 想要完全控制Mongo实例的配置和日志路由,你可以声明自己的`IMongodConfig`和`IRuntimeConfig` beans。
9 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/74.10 Expose Spring Data repositories as REST endpoint.md:
--------------------------------------------------------------------------------
1 | ### 74.10 将Spring Data仓库暴露为REST端点
2 |
3 | Spring Data REST能够将`Repository`的实现暴露为REST端点,只要该应用启用Spring MVC。Spring Boot暴露一系列来自`spring.data.rest`命名空间的有用属性来定制化[RepositoryRestConfiguration](http://docs.spring.io/spring-data/rest/docs/current/api/org/springframework/data/rest/core/config/RepositoryRestConfiguration.html),你可以使用[`RepositoryRestConfigurer`](http://docs.spring.io/spring-data/rest/docs/current/api/org/springframework/data/rest/webmvc/config/RepositoryRestConfigurer.html)提供其他定制。
4 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/80.9 Remote debug a Spring Boot application started with Gradle.md:
--------------------------------------------------------------------------------
1 | ### 80.9 远程调试使用Gradle启动的Spring Boot项目
2 |
3 | 想要为使用Gradle启动的Spring Boot应用添加一个远程调试器,你可以使用`build.gradle`的`applicationDefaultJvmArgs`属性或`--debug-jvm`命令行选项。
4 |
5 | build.gradle:
6 | ```gradle
7 | applicationDefaultJvmArgs = [
8 | "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005"
9 | ]
10 | ```
11 | 命令行:
12 | ```shell
13 | $ gradle run --debug-jvm
14 | ```
15 | 详情查看[Gradle应用插件](http://www.gradle.org/docs/current/userguide/application_plugin.html)。
16 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/78.1 Switch off the Spring Boot security configuration.md:
--------------------------------------------------------------------------------
1 | ### 78.1 关闭Spring Boot安全配置
2 |
3 | 不管你在应用的什么地方定义了一个使用`@EnableWebSecurity`注解的`@Configuration`,它都会关闭Spring Boot中的默认webapp安全设置。想要调整默认值,你可以尝试设置`security.*`属性(具体查看[SecurityProperties](http://github.com/spring-projects/spring-boot/tree/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityProperties.java)和[常见应用属性](http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#common-application-properties-security)的SECURITY章节)。
4 |
--------------------------------------------------------------------------------
/I. Spring Boot Documentation/1. About the documentation.md:
--------------------------------------------------------------------------------
1 | ### 1. 关于本文档
2 |
3 | Spring Boot参考指南有[html](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/html),[pdf](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/pdf/spring-boot-reference.pdf)和[epub](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/epub/spring-boot-reference.epub)等形式的文档,你可以从[docs.spring.io/spring-boot/docs/current/reference](http://docs.spring.io/spring-boot/docs/current/reference)获取到最新版本。
4 |
5 | 对本文档的拷贝,不管是电子版还是打印,在保证包含版权声明,并且不收取任何费用的情况下,你可以自由使用,或分发给其他人。
6 |
--------------------------------------------------------------------------------
/II. Getting started/11.3.1. The @RestController and @RequestMapping annotations.md:
--------------------------------------------------------------------------------
1 |
2 | ### 11.3.1. @RestController和@RequestMapping注解
3 |
4 | Example类上使用的第一个注解是`@RestController`,这被称为构造型(stereotype)注解。它为阅读代码的人提供暗示(这是一个支持REST的控制器),对于Spring,该类扮演了一个特殊角色。在本示例中,我们的类是一个web `@Controller`,所以当web请求进来时,Spring会考虑是否使用它来处理。
5 |
6 | `@RequestMapping`注解提供路由信息,它告诉Spring任何来自"/"路径的HTTP请求都应该被映射到`home`方法。`@RestController`注解告诉Spring以字符串的形式渲染结果,并直接返回给调用者。
7 |
8 | **注**:`@RestController`和`@RequestMapping`是Spring MVC中的注解(它们不是Spring Boot的特定部分),具体参考Spring文档的[MVC章节](http://mvc.linesh.tw)。
9 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/29.5.3 Customizing jOOQ.md:
--------------------------------------------------------------------------------
1 | ### 29.5.3 自定义jOOQ
2 | 通过在`application.properties`中设置`spring.jooq.sql-dialect`属性,你可以自定义jOOQ使用的SQL方言(dialect)。例如,设置方言为Postgres:
3 | ```properties
4 | spring.jooq.sql-dialect=Postgres
5 | ```
6 | 定义自己的`@Bean`,在jOOQ`Configuration`创建时使用,可以实现更高级的定制。你可以为以下jOOQ类型定义beans:
7 |
8 | * `ConnectionProvider`
9 | * `TransactionProvider`
10 | * `RecordMapperProvider`
11 | * `RecordListenerProvider`
12 | * `ExecuteListenerProvider`
13 | * `VisitListenerProvider`
14 |
15 | 如果想全面控制jOOQ配置,你甚至可以创建自己的`org.jooq.Configuration` `@Bean`。
16 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/69.8 Discover built-in options for external properties.md:
--------------------------------------------------------------------------------
1 |
2 | ### 69.8 发现外部属性的内置选项
3 |
4 | Spring Boot在运行时会将来自`application.properties`(或`.yml`)的外部属性绑定到应用,因为不可能将所有支持的属性放到一个地方,classpath下的其他jar也有支持的属性。
5 |
6 | 每个运行中且有Actuator特性的应用都会有一个`configprops`端点,它能够展示所有边界和可通过`@ConfigurationProperties`绑定的属性。
7 |
8 | 附录中包含一个[application.properties](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/htmlsingle/#common-application-properties)示例,它列举了Spring Boot支持的大多数常用属性,查看`@ConfigurationProperties`,`@Value`,还有不经常使用的`RelaxedEnvironment`的源码可获取最权威的属性列表。
9 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/74.2 Configure Two DataSources.md:
--------------------------------------------------------------------------------
1 | ### 74.2 配置两个数据源
2 |
3 | 创建多个数据源和创建一个工作都是一样的,如果使用JDBC或JPA的默认自动配置,你需要将其中一个设置为`@Primary`(然后它就能被任何`@Autowired`注入获取)。
4 | ```java
5 | @Bean
6 | @Primary
7 | @ConfigurationProperties(prefix="datasource.primary")
8 | public DataSource primaryDataSource() {
9 | return DataSourceBuilder.create().build();
10 | }
11 |
12 | @Bean
13 | @ConfigurationProperties(prefix="datasource.secondary")
14 | public DataSource secondaryDataSource() {
15 | return DataSourceBuilder.create().build();
16 | }
17 | ```
18 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/46.7.3 Git commit information.md:
--------------------------------------------------------------------------------
1 | ### 46.7.3 Git提交信息
2 | `info`端点的另一个有用特性是,在项目构建完成后发布`git`源码仓库的状态信息。如果`GitProperties` bean可用,Spring Boot将暴露`git.branch`,`git.commit.id`和`git.commit.time`属性。
3 |
4 | **注** 如果classpath根目录存在`git.properties`文件,Spring Boot将自动配置`GitProperties` bean。查看[Generate git information](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/htmlsingle/#howto-git-info)获取更多详细信息。
5 |
6 | 使用`management.info.git.mode`属性可展示全部git信息(比如`git.properties`全部内容):
7 | ```properties
8 | management.info.git.mode=full
9 | ```
10 |
--------------------------------------------------------------------------------
/III. Using Spring Boot/20.1 Property defaults.md:
--------------------------------------------------------------------------------
1 | ###20.1 默认属性
2 |
3 | Spring Boot支持的一些库(libraries)使用缓存提高性能,比如Thymeleaf将缓存模板以避免重复解析XML源文件。虽然缓存在生产环境很有用,但开发期间就是个累赘了。如果在IDE里修改了模板,你可能会想立即看到结果。
4 |
5 | 缓存选项通常配置在`application.properties`文件中,比如Thymeleaf提供了`spring.thymeleaf.cache`属性,`spring-boot-devtools`模块会自动应用敏感的`development-time`配置,而不是手动设置这些属性。
6 |
7 | **注** 查看[DevToolsPropertyDefaultsPostProcessor](https://github.com/spring-projects/spring-boot/tree/master/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsPropertyDefaultsPostProcessor.java)获取完整的被应用的属性列表。
8 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/32.2.1 RabbitMQ support.md:
--------------------------------------------------------------------------------
1 | ###32.2.1 RabbitMQ支持
2 | RabbitMQ是一个基于AMQP协议,轻量级的,可靠的,可扩展的和可移植的消息代理,Spring就使用它进行消息传递。RabbitMQ配置被外部属性`spring.rabbitmq.*`控制,例如,在`application.properties`中声明以下片段:
3 | ```properties
4 | spring.rabbitmq.host=localhost
5 | spring.rabbitmq.port=5672
6 | spring.rabbitmq.username=admin
7 | spring.rabbitmq.password=secret
8 | ```
9 | 更多选项参考[RabbitProperties](https://github.com/spring-projects/spring-boot/tree/v1.4.1.RELEASE/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java)。
10 |
--------------------------------------------------------------------------------
/VIII. Build tool plugins/64.4 Running a project in-place.md:
--------------------------------------------------------------------------------
1 | ### 64.4 就地(in-place)运行项目
2 |
3 | 为了在不先构建jar的情况下运行项目,你可以使用`bootRun`任务:
4 | ```shell
5 | $ gradle bootRun
6 | ```
7 | 如果项目中添加了[devtools](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/htmlsingle/#using-boot-devtools),它将自动监控你的应用变动。此外,你可以运行应用,这样静态classpath资源(比如,默认位于`src/main/resources`下)在应用运行期间将能够重新加载,这在开发期间是非常有用的:
8 | ```gradle
9 | bootRun {
10 | addResources = true
11 | }
12 | ```
13 | 让静态classpath资源可加载意味着`bootRun`不使用`processResources`任务的输出,例如,当使用`bootRun`调用时,你的应用将以未经处理的形式使用资源。
14 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/26.3. File output.md:
--------------------------------------------------------------------------------
1 | ### 26.3. 文件输出
2 |
3 | 默认情况下,Spring Boot只会将日志记录到控制台,而不写进日志文件,如果需要,你可以设置`logging.file`或`logging.path`属性(例如`application.properties`)。
4 |
5 | 下表展示如何组合使用`logging.*`:
6 |
7 | |logging.file|logging.path| 示例 | 描述 |
8 | | -------- | :----- | :----- | :-----|
9 | | (none) | (none) | | 只记录到控制台 |
10 | |Specific file|(none)|my.log|写到特定的日志文件,名称可以是精确的位置或相对于当前目录|
11 | |(none)|Specific directory|/var/log|写到特定目录下的`spring.log`里,名称可以是精确的位置或相对于当前目录|
12 |
13 | 日志文件每达到10M就会被分割,跟控制台一样,默认记录`ERROR`, `WARN`和`INFO`级别的信息。
14 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/70.18.2 Use Jetty 8 with Gradle.md:
--------------------------------------------------------------------------------
1 | ### 70.18.2 通过Gradle使用Jetty8
2 |
3 | 你可以设置`jetty.version`属性并排除相关的WebSocket依赖,比如对于一个简单的webapp或service:
4 | ```gradle
5 | ext['jetty.version'] = '8.1.15.v20140411'
6 | dependencies {
7 | compile ('org.springframework.boot:spring-boot-starter-web') {
8 | exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
9 | }
10 | compile ('org.springframework.boot:spring-boot-starter-jetty') {
11 | exclude group: 'org.eclipse.jetty.websocket'
12 | }
13 | }
14 | ```
15 |
--------------------------------------------------------------------------------
/III. Using Spring Boot/19.1. Running from an IDE.md:
--------------------------------------------------------------------------------
1 | ### 19.1. 从IDE中运行
2 |
3 | 你可以从IDE中运行Spring Boot应用,就像一个简单的Java应用,但首先需要导入项目。导入步骤取决于你的IDE和构建系统,大多数IDEs能够直接导入Maven项目,例如Eclipse用户可以选择`File`菜单的`Import…` --> `Existing Maven Projects`。
4 |
5 | 如果不能直接将项目导入IDE,你可以使用构建系统生成IDE的元数据。Maven有针对[Eclipse](http://maven.apache.org/plugins/maven-eclipse-plugin/)和[IDEA](http://maven.apache.org/plugins/maven-idea-plugin/)的插件;Gradle为[各种IDEs](http://www.gradle.org/docs/current/userguide/ide_support.html)提供插件。
6 |
7 | **注** 如果意外地多次运行一个web应用,你将看到一个"端口已被占用"的错误。STS用户可以使用`Relaunch`而不是`Run`按钮,以确保任何存在的实例是关闭的。
8 |
--------------------------------------------------------------------------------
/III. Using Spring Boot/13.2.4. Using the Spring Boot Maven plugin.md:
--------------------------------------------------------------------------------
1 | ### 13.2.4. 使用Spring Boot Maven插件
2 |
3 | Spring Boot包含一个[Maven插件](../VIII. Build tool plugins/58. Spring Boot Maven plugin.md),它可以将项目打包成一个可执行jar。如果想使用它,你可以将该插件添加到``节点处:
4 | ```xml
5 |
6 |
7 |
8 | org.springframework.boot
9 | spring-boot-maven-plugin
10 |
11 |
12 |
13 | ```
14 | **注**:如果使用Spring Boot starter parent pom,你只需添加该插件而无需配置它,除非你想改变定义在partent中的设置。
15 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/25. Profiles.md:
--------------------------------------------------------------------------------
1 | ### 25. Profiles
2 | Spring Profiles提供了一种隔离应用程序配置的方式,并让这些配置只在特定的环境下生效。任何`@Component`或`@Configuration`都能注解`@Profile`,从而限制加载它的时机:
3 | ```java
4 | @Configuration
5 | @Profile("production")
6 | public class ProductionConfiguration {
7 |
8 | // ...
9 |
10 | }
11 | ```
12 | 以正常的Spring方式,你可以使用`spring.profiles.active`的`Environment`属性来指定哪个配置生效。你可以使用通常的任何方式来指定该属性,例如,可以将它包含到`application.properties`中:
13 | ```java
14 | spring.profiles.active=dev,hsqldb
15 | ```
16 | 或使用命令行开关:
17 | ```shell
18 | --spring.profiles.active=dev,hsqldb
19 | ```
20 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/28.1.1 Authorization Server.md:
--------------------------------------------------------------------------------
1 | ### 28.1.1 授权服务器
2 |
3 | 想要创建一个授权服务器,并授予access tokens,你需要使用`@EnableAuthorizationServer`,并提供`security.oauth2.client.client-id`和`security.oauth2.client.client-secret`配置。
4 |
5 | 按以上操作后,你就能使用客户端证书创建一个access token,例如:
6 | ```shell
7 | $ curl client:secret@localhost:8080/oauth/token -d grant_type=password -d username=user -d password=pwd
8 | ```
9 | `/token`端点basic形式的认证证书是`client-id`和`client-secret`,用户证书通常是Spring Security的user详情(Spring Boot中默认是"user"和一个随机的密码)。
10 |
11 | 想要关闭自动配置,自己配置授权服务器特性,你只需添加一个`AuthorizationServerConfigurer`类型的`@Bean`。
12 |
--------------------------------------------------------------------------------
/VII. Spring Boot CLI/59.4 Packaging your application.md:
--------------------------------------------------------------------------------
1 | ### 59.4 应用打包
2 |
3 | 你可以使用`jar`命令打包应用程序为一个可执行的jar文件,例如:
4 | ```shell
5 | $ spring jar my-app.jar *.groovy
6 | ```
7 | 最终的jar包括编译应用产生的类和所有依赖,这样你就可以使用`java -jar`来执行它了。该jar文件也包含了来自应用classpath的实体。你可以使用`--include`和`--exclude`添加明确的路径(两者都是用逗号分割,同样都接收值为'+'和'-'的前缀,'-'意味着它们将从默认设置中移除),默认包含(includes):
8 | ```shell
9 | public/**, resources/**, static/**, templates/**, META-INF/**, *
10 | ```
11 | 默认排除(excludes):
12 | ```shell
13 | .*, repository/**, build/**, target/**, **/*.jar, **/*.groovy
14 | ```
15 | 查看`spring help jar`可以获得更多信息。
16 |
--------------------------------------------------------------------------------
/II. Getting started/10.2.6. Quick start Spring CLI example.md:
--------------------------------------------------------------------------------
1 | ### 10.2.6. Spring CLI示例快速入门
2 |
3 | 下面是一个相当简单的web应用,你可以用它测试Spring CLI安装是否成功。创建一个名叫`app.groovy`的文件:
4 | ```groovy
5 | @RestController
6 | class ThisWillActuallyRun {
7 |
8 | @RequestMapping("/")
9 | String home() {
10 | "Hello World!"
11 | }
12 |
13 | }
14 | ```
15 | 然后只需在shell中运行以下命令:
16 | ```shell
17 | $ spring run app.groovy
18 | ```
19 | **注**:首次运行该应用将会花费一些时间,因为需要下载依赖,后续运行将会快很多。
20 |
21 | 使用你最喜欢的浏览器打开[localhost:8080](localhost:8080),然后就可以看到如下输出:
22 | ```java
23 | Hello World!
24 | ```
25 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/34. Sending email.md:
--------------------------------------------------------------------------------
1 | ### 34. 发送邮件
2 | Spring框架通过`JavaMailSender`接口为发送邮件提供了一个简单的抽象,并且Spring Boot也为它提供了自动配置和一个starter模块。
3 | 具体查看[JavaMailSender参考文档](http://docs.spring.io/spring/docs/4.3.3.RELEASE/spring-framework-reference/htmlsingle/#mail)。
4 |
5 | 如果`spring.mail.host`和相关的libraries(通过`spring-boot-starter-mail`定义的)都可用,Spring Boot将创建一个默认的`JavaMailSender`,该sender可以通过`spring.mail`命名空间下的配置项进一步自定义,具体参考[MailProperties](http://github.com/spring-projects/spring-boot/tree/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mail/MailProperties.java)。
6 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/50.3 Cache metrics.md:
--------------------------------------------------------------------------------
1 | ###50.3 缓存指标
2 | Spring Boot会为应用中定义的每个支持的缓存暴露以下指标:
3 | - cache当前大小(`cache.xxx.size`)
4 | - 命中率(`cache.xxx.hit.ratio`)
5 | - 丢失率(`cache.xxx.miss.ratio`)
6 |
7 | **注** 缓存提供商没有以一致的方式暴露命中/丢失率,有些暴露的是聚合(aggregated)值(比如,自从统计清理后的命中率),而其他暴露的是时序(temporal)值
8 | (比如,最后一秒的命中率),具体查看缓存提供商的文档。
9 |
10 | 如果两个不同的缓存管理器恰巧定义了相同的缓存,缓存name将以`CacheManager` bean的name作为前缀。
11 |
12 | 注册自定义版本的`CachePublicMetrics`可以部分或全部覆盖这些默认值,Spring Boot默认为EhCache,Hazelcast,Infinispan,JCache和Guava提供统计。如果喜欢的缓存库没被支持,你可以添加其他`CacheStatisticsProvider` beans,具体可参考`CacheStatisticsAutoConfiguration`。
13 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/50.10 Dropwizard Metrics.md:
--------------------------------------------------------------------------------
1 | ### 50.10 Dropwizard指标
2 | 当你声明对`io.dropwizard.metrics:metrics-core`的依赖时,Spring Boot会创建一个默认的`MetricRegistry` bean。如果需要自定义,你可以注册自己的`@Bean`实例。使用[Dropwizard ‘Metrics’ library](https://dropwizard.github.io/metrics/)的用户会发现Spring Boot指标自动发布到`com.codahale.metrics.MetricRegistry`,来自`MetricRegistry`的指标也自动暴露到`/metrics`端点。
3 |
4 | 使用Dropwizard指标时,默认的`CounterService`和`GaugeService`被`DropwizardMetricServices`替换,它是一个`MetricRegistry`的包装器(所以你可以`@Autowired`其中任意services,并像平常那么使用它)。通过使用恰当的前缀类型标记你的指标名可以创建特殊的Dropwizard指标服务(比如,gauges使用`timer.*`,`histogram.*`,counters使用`meter.*`)。
5 |
--------------------------------------------------------------------------------
/I. Spring Boot Documentation/3. First steps.md:
--------------------------------------------------------------------------------
1 | ### 3. 第一步
2 |
3 | 如果你想对Spring Boot或Spring有个整体认识,可以从[这里开始](../II. Getting started/README.md)!
4 |
5 | - 从零开始:[概述](../II. Getting started/8. Introducing Spring Boot.md)|[要求](../II. Getting started/9. System Requirements.md)|[安装](../II. Getting started/10. Installing Spring Boot.md)
6 | - 教程:[第一部分](../II. Getting started/11. Developing your first Spring Boot application.md)|[第二部分](../II. Getting started/11.3. Writing the code.md)
7 | - 运行示例:[第一部分](../II. Getting started/11.4. Running the example.md)|[第二部分](../II. Getting started/11.5. Creating an executable jar.md)
8 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/26. Logging.md:
--------------------------------------------------------------------------------
1 | ### 26. 日志
2 | Spring Boot内部日志系统使用的是[Commons Logging](http://commons.apache.org/logging),但开放底层的日志实现,默认为会[Java Util Logging](http://docs.oracle.com/javase/7/docs/api/java/util/logging/package-summary.html), [Log4J](http://logging.apache.org/log4j/), [Log4J2](http://logging.apache.org/log4j/2.x/)和[Logback](http://logback.qos.ch/)提供配置。每种情况下都预先配置使用控制台输出,也可以使用可选的文件输出。
3 |
4 | 默认情况下,如果你使用'Starters',那么就会使用Logback记录日志。为了确保使用Java Util Logging, Commons Logging, Log4J或SLF4J的依赖库能够正常工作,相应的Logback路由也会包含进来。
5 |
6 | **注** 如果上面的列表看起来令人困惑,不要担心,Java有很多可用的日志框架。通常,你不需要改变日志依赖,Spring Boot默认的就能很好的工作。
7 |
--------------------------------------------------------------------------------
/X. Appendices/D.3.1. Launcher manifest.md:
--------------------------------------------------------------------------------
1 | ### 附录D.3.1 Launcher manifest
2 |
3 | 你需要指定一个合适的Launcher作为`META-INF/MANIFEST.MF`的`Main-Class`属性。你实际想要启动的类(也就是你编写的包含main方法的类)需要在`Start-Class`属性中定义。
4 |
5 | 例如,这里有个典型的可执行jar文件的MANIFEST.MF:
6 | ```properties
7 | Main-Class: org.springframework.boot.loader.JarLauncher
8 | Start-Class: com.mycompany.project.MyApplication
9 | ```
10 | 对于一个war文件,它可能是这样的:
11 | ```properties
12 | Main-Class: org.springframework.boot.loader.WarLauncher
13 | Start-Class: com.mycompany.project.MyApplication
14 | ```
15 | **注**:你不需要在manifest文件中指定`Class-Path`实体,classpath会从嵌套的jars中被推导出来。
16 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/40.3.2 Excluding test configuration.md:
--------------------------------------------------------------------------------
1 | ###40.3.2 排除测试配置
2 | 如果应用使用组件扫描,比如`@SpringBootApplication`或`@ComponentScan`,你可能发现为测试类创建的组件或配置在任何地方都可能偶然扫描到。为了防止这种情况,Spring Boot提供了`@TestComponent`和`@TestConfiguration`注解,可用在`src/test/java`目录下的类,以暗示它们不应该被扫描。
3 |
4 | **注** 只有上层类需要`@TestComponent`和`@TestConfiguration`注解,如果你在测试类(任何有`@Test`方法或`@RunWith`注解的类)中定义`@Configuration`或`@Component`内部类,它们将被自动过滤。
5 |
6 | **注** 如果直接使用`@ComponentScan`(比如不通过`@SpringBootApplication`),你需要为它注册`TypeExcludeFilter`,具体参考[Javadoc](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/api/org/springframework/boot/context/TypeExcludeFilter.html)。
7 |
--------------------------------------------------------------------------------
/VIII. Build tool plugins/66.4. Example repackage implementation.md:
--------------------------------------------------------------------------------
1 | ### 66.4. repackage实现示例
2 |
3 | 这是一个典型的repackage示例:
4 | ```java
5 | Repackager repackager = new Repackager(sourceJarFile);
6 | repackager.setBackupSource(false);
7 | repackager.repackage(new Libraries() {
8 | @Override
9 | public void doWithLibraries(LibraryCallback callback) throws IOException {
10 | // Build system specific implementation, callback for each dependency
11 | // callback.library(new Library(nestedFile, LibraryScope.COMPILE));
12 | }
13 | });
14 | ```
15 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/47.1 Securing sensitive endpoints.md:
--------------------------------------------------------------------------------
1 | ### 47.1 保护敏感端点
2 | 如果你的项目添加了‘Spring Security’依赖,所有通过HTTP暴露的敏感端点都会受到保护,默认情况下会使用用户名为`user`的基本认证(basic authentication),产生的密码会在应用启动时打印到控制台上。
3 |
4 | **注** 在应用启动时会记录生成的密码,具体搜索`Using default security password`。
5 |
6 | 你可以使用Spring属性改变用户名,密码和访问端点需要的安全角色。例如,你可以将以下配置添加到`application.properties`中:
7 | ```java
8 | security.user.name=admin
9 | security.user.password=secret
10 | management.security.role=SUPERUSER
11 | ```
12 |
13 | **注** 如果不使用Spring Security,并且公开暴露HTTP端点,你应该慎重考虑启用哪些端点,具体参考[Section 46.1, “Customizing endpoints”](40.1. Customizing endpoints.md)。
14 |
--------------------------------------------------------------------------------
/VIII. Build tool plugins/64.1 Including the plugin.md:
--------------------------------------------------------------------------------
1 | ### 64.1 包含该插件
2 |
3 | 想要使用Spring Boot Gradle插件,你只需简单的包含一个`buildscript`依赖,并应用`spring-boot`插件:
4 | ```gradle
5 | buildscript {
6 | dependencies {
7 | classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.1.RELEASE")
8 | }
9 | }
10 | apply plugin: 'spring-boot'
11 | ```
12 | 如果使用的是一个里程碑或快照版本,你需要添加相应的`repositories`引用:
13 | ```gradle
14 | buildscript {
15 | repositories {
16 | maven.url "http://repo.spring.io/snapshot"
17 | maven.url "http://repo.spring.io/milestone"
18 | }
19 | // ...
20 | }
21 | ```
22 |
--------------------------------------------------------------------------------
/VIII. Build tool plugins/65.1.1. spring-boot:exejar.md:
--------------------------------------------------------------------------------
1 | ###65.1.1. spring-boot:exejar
2 |
3 | `exejar`任务可用于创建Spring Boot可执行jar,该任务支持以下属性:
4 |
5 | |属性|描述|是否必须|
6 | |:----|:----|:-----|
7 | |`destfile`|将要创建的目的jar文件|是|
8 | |`classes`|Java类文件的根目录|是|
9 | |`start-class`|运行的main类|否(默认为找到的第一个声明`main`方法的类)|
10 |
11 | 以下元素可以跟任务一块使用:
12 |
13 | |元素|描述|
14 | |:----|:----|
15 | |`resources`|一个或多个[Resource Collections](http://ant.apache.org/manual/Types/resources.html#collection),描述将添加到创建的jar文件中的资源集合|
16 | |`lib`|一个或多个[Resource Collections](http://ant.apache.org/manual/Types/resources.html#collection),表示需要添加进jar库的集合,组成了应用运行时的classpath依赖|
17 |
--------------------------------------------------------------------------------
/VIII. Build tool plugins/65.1.2. Examples.md:
--------------------------------------------------------------------------------
1 | ### 65.1.2. 示例
2 |
3 | **指定start-class**
4 | ```xml
5 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | ```
15 |
16 | **探测start-class**
17 | ```xml
18 |
19 |
20 |
21 |
22 |
23 | ```
24 |
--------------------------------------------------------------------------------
/II. Getting started/10.2.5. Command-line completion.md:
--------------------------------------------------------------------------------
1 | ### 10.2.5. 命令行实现
2 |
3 | Spring Boot CLI启动脚本为[BASH](http://en.wikipedia.org/wiki/Bash_%28Unix_shell%29)和[zsh](http://en.wikipedia.org/wiki/Zsh) shells提供完整的命令行实现。你可以在任何shell中source脚本(名称也是spring),或将它放到用户或系统范围内的bash初始化脚本里。在Debian系统中,系统级的脚本位于`/shell-completion/bash`下,当新的shell启动时该目录下的所有脚本都会被执行。如果想要手动运行脚本,假如你已经安装了SDKMAN,可以使用以下命令:
4 | ```shell
5 | $ . ~/.sdkman/candidates/springboot/current/shell-completion/bash/spring
6 | $ spring
7 | grab help jar run test version
8 | ```
9 |
10 | **注**:如果你使用Homebrew或MacPorts安装Spring Boot CLI,命令行实现脚本会自动注册到你的shell。
11 |
--------------------------------------------------------------------------------
/VIII. Build tool plugins/64.7.1 Configuration options.md:
--------------------------------------------------------------------------------
1 | ### 64.7.1 配置选项
2 |
3 | 可用的配置选项如下:
4 |
5 | |名称|描述|
6 | |-------|:--------|
7 | |`mainClass`|可执行jar运行的main类|
8 | |`providedConfiguration`|provided配置的名称(默认为`providedRuntime`)|
9 | |`backupSource`|在重新打包之前,原先的存档是否备份(默认为`true`)|
10 | |`customConfiguration`|自定义配置的名称|
11 | |`layout`|存档类型,对应于内部依赖是如何制定的(默认基于存档类型进行推测),具体查看[available layouts](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/htmlsingle/#build-tool-plugins-gradle-configuration-layouts)|
12 | |`requiresUnpack`|一个依赖列表(格式为"groupId:artifactId",为了运行,它们需要从fat jars中解压出来。)所有节点被打包进胖jar,但运行的时候它们将被自动解压|
13 |
--------------------------------------------------------------------------------
/II. Getting started/12. What to read next.md:
--------------------------------------------------------------------------------
1 | ### 12. 接下来阅读什么
2 |
3 | 希望本章节已为你提供一些Spring Boot的基础部分,并帮你找到开发自己应用的方式。如果你是任务驱动型的开发者,那可以直接跳到[spring.io](http://spring.io/),check out一些[入门指南](http://spring.io/guides/),以解决特定的"使用Spring如何做"的问题;我们也有Spring Boot相关的[How-to](../IX. ‘How-to’ guides/README.md)参考文档。
4 |
5 | [Spring Boot仓库](http://github.com/spring-projects/spring-boot)有大量可以运行的[示例](https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples),这些示例代码是彼此独立的(运行或使用示例的时候不需要构建其他示例)。
6 |
7 | 否则,下一步就是阅读 [III、使用Spring Boot](../III. Using Spring Boot/README.md),如果没耐心,可以跳过该章节,直接阅读 [IV、Spring Boot特性](../IV. Spring Boot features/README.md)。
8 |
--------------------------------------------------------------------------------
/VII. Spring Boot CLI/59.2 Testing your code.md:
--------------------------------------------------------------------------------
1 | ### 59.2 测试你的代码
2 |
3 | `test`命令允许你编译和运行应用程序的测试用例,常规使用方式如下:
4 | ```shell
5 | $ spring test app.groovy tests.groovy
6 | Total: 1, Success: 1, : Failures: 0
7 | Passed? true
8 | ```
9 | 在这个示例中,`test.groovy`包含JUnit `@Test`方法或Spock `Specification`类。所有的普通框架注解和静态方法在不使用`import`导入的情况下,仍旧可以使用。
10 |
11 | 下面是我们使用的`test.groovy`文件(含有一个JUnit测试):
12 | ```java
13 | class ApplicationTests {
14 |
15 | @Test
16 | void homeSaysHello() {
17 | assertEquals("Hello World!", new WebApplication().home())
18 | }
19 |
20 | }
21 | ```
22 | **注** 如果有多个测试源文件,你可能倾向于将它们放到`test`目录下。
23 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/27.3.1 Servlets, Filters, and listeners.md:
--------------------------------------------------------------------------------
1 | ### 27.3.1 Servlets, Filters和listeners
2 |
3 | 使用内嵌servlet容器时,你可以通过使用Spring beans或扫描Servlet组件的方式注册Servlets,Filters及特定Servlet相关的所有listeners(比如`HttpSessionListener`)。
4 |
5 | **将Servlets,Filters和listeners注册为Spring beans**
6 |
7 | 所有`Servlet`,`Filter`或Servlet `*Listener`实例,只要是Spring bean,都会注册到内嵌容器中。如果想在配置期间引用`application.properties`的属性,这是非常方便的。默认情况下,如果上下文只包含单个Servlet,那它将被映射到`/`。如果存在多个Servlet beans,那么bean的名称将被用作路径的前缀,过滤器将映射到`/*`。
8 |
9 | 如果基于约定(convention-based)的映射不够灵活,你可以使用`ServletRegistrationBean`,`FilterRegistrationBean`,`ServletListenerRegistrationBean`实现完全的控制。
10 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/29.2. Using JdbcTemplate.md:
--------------------------------------------------------------------------------
1 | ### 29.2. 使用JdbcTemplate
2 |
3 | Spring的`JdbcTemplate`和`NamedParameterJdbcTemplate`类会被自动配置,你可以将它们直接`@Autowire`到自己的beans:
4 | ```java
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.jdbc.core.JdbcTemplate;
7 | import org.springframework.stereotype.Component;
8 |
9 | @Component
10 | public class MyBean {
11 |
12 | private final JdbcTemplate jdbcTemplate;
13 |
14 | @Autowired
15 | public MyBean(JdbcTemplate jdbcTemplate) {
16 | this.jdbcTemplate = jdbcTemplate;
17 | }
18 | // ...
19 | }
20 | ```
21 |
--------------------------------------------------------------------------------
/IX. ‘How-to’ guides/70.2 Change the HTTP port.md:
--------------------------------------------------------------------------------
1 | ### 70.2 改变HTTP端口
2 |
3 | 在一个单独的应用中,主HTTP端口默认为`8080`,不过可以使用`server.port`设置(比如,在`application.properties`中或作为系统属性)。由于`Environment`值的宽松绑定,你也可以使用`SERVER_PORT`(比如,作为OS环境变量)。
4 |
5 | 想要创建`WebApplicationContext`但完全关闭HTTP端点,你可以设置`server.port=-1`(测试时可能有用)。具体详情可查看'Spring Boot特性'章节的[Section 27.3.4, “Customizing embedded servlet containers”](../IV. Spring Boot features/27.3.4 Customizing embedded servlet containers.md),或[ServerProperties](https://github.com/spring-projects/spring-boot/tree/v1.4.1.RELEASE/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java)源码。
6 |
--------------------------------------------------------------------------------
/V. Spring Boot Actuator/50.2 DataSource metrics.md:
--------------------------------------------------------------------------------
1 | ### 50.2 数据源指标
2 | Spring Boot会为应用中定义的每个支持的`DataSource`暴露以下指标:
3 | - 活动连接数(`datasource.xxx.active`)
4 | - 连接池当前使用情况(`datasource.xxx.usage`)
5 |
6 | 所有数据源指标共用`datasoure.`前缀,该前缀适用于每个数据源:
7 | - 如果是主数据源(唯一可用的数据源或注解`@Primary`的数据源)前缀为`datasource.primary`。
8 | - 如果数据源bean名称以`DataSource`结尾,前缀就是bean的名称去掉`DataSource`的部分(比如,`batchDataSource`的前缀是`datasource.batch`)。
9 | - 其他情况使用bean的名称作为前缀。
10 |
11 | 通过注册自定义版本的`DataSourcePublicMetrics` bean,你可以覆盖部分或全部的默认行为。Spring Boot默认提供支持所有数据源的元数据,如果喜欢的数据源恰好不被支持,你可以添加其他的`DataSourcePoolMetadataProvider` beans,具体参考`DataSourcePoolMetadataProvidersConfiguration`。
12 |
--------------------------------------------------------------------------------
/VII. Spring Boot CLI/59.7 Adding extensions to the CLI.md:
--------------------------------------------------------------------------------
1 | ### 59.7 为CLI添加扩展
2 |
3 | 使用`install`命令可以为CLI添加扩展,该命令接收一个或多个格式为`group:artifact:version`的artifact坐标集,例如:
4 | ```shell
5 | $ spring install com.example:spring-boot-cli-extension:1.0.0.RELEASE
6 | ```
7 | 除安装你提供坐标的artifacts标识外,该artifacts的所有依赖也会被安装。
8 |
9 | 使用`uninstall`可以卸载一个依赖,和`install`命令一样,它也接收一个或多个格式为`group:artifact:version`的artifact坐标集,例如:
10 | ```shell
11 | $ spring uninstall com.example:spring-boot-cli-extension:1.0.0.RELEASE
12 | ```
13 | 它会通过你提供的坐标卸载相应的artifacts标识及它们的依赖。
14 |
15 | 为了卸载所有附加依赖,你可以使用`--all`选项,例如:
16 | ```shell
17 | $ spring uninstall --all
18 | ```
19 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/40.4.1 ConfigFileApplicationContextInitializer.md:
--------------------------------------------------------------------------------
1 | ###40.4.1 ConfigFileApplicationContextInitializer
2 |
3 | `ConfigFileApplicationContextInitializer`是一个`ApplicationContextInitializer`,可在测试类中用于加载Spring Boot的`application.properties`文件。当不需要使用`@SpringBootTest`提供的全部特性时,你可以使用它。
4 |
5 | ```java
6 | @ContextConfiguration(classes = Config.class,initializers = ConfigFileApplicationContextInitializer.class)
7 | ```
8 | **注** 单独使用`ConfigFileApplicationContextInitializer`不会提供`@Value("${…}")`注入支持,它只负责确保`application.properties`文件加载进Spring的`Environment`。为了`@Value`支持,你需要额外配置一个`PropertySourcesPlaceholderConfigurer`或使用`@SpringBootTest`为你自动配置一个。
9 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/30.1.1. Connecting to Redis.md:
--------------------------------------------------------------------------------
1 | ### 30.1.1. 连接Redis
2 |
3 | 你可以注入一个自动配置的`RedisConnectionFactory`,`StringRedisTemplate`或普通的`RedisTemplate`实例,或任何其他Spring Bean只要你愿意。默认情况下,这个实例将尝试使用`localhost:6379`连接Redis服务器:
4 | ```java
5 | @Component
6 | public class MyBean {
7 |
8 | private StringRedisTemplate template;
9 |
10 | @Autowired
11 | public MyBean(StringRedisTemplate template) {
12 | this.template = template;
13 | }
14 | // ...
15 | }
16 | ```
17 | 如果你添加一个自己的,或任何自动配置类型的`@Bean`,它将替换默认实例(除了`RedisTemplate`的情况,它是根据`bean`的name 'redisTemplate'而不是类型进行排除的)。如果在classpath路径下存在`commons-pool2`,默认你会获得一个连接池工厂。
18 |
--------------------------------------------------------------------------------
/IV. Spring Boot features/31.1.9 Guava.md:
--------------------------------------------------------------------------------
1 | ###31.1.9 Guava
2 | 如果存在Guava,`GuavaCacheManager`会自动配置。使用`spring.cache.cache-names`属性可以在启动时创建缓存,并通过以下方式之一自定义(按此顺序):
3 |
4 | 1. `spring.cache.guava.spec`定义的特殊缓存
5 | 2. `com.google.common.cache.CacheBuilderSpec` bean定义的
6 | 3. `com.google.common.cache.CacheBuilder` bean定义的
7 |
8 | 例如,以下配置创建了一个`foo`和`bar`缓存,该缓存最大数量为500,存活时间为10分钟:
9 | ```properties
10 | spring.cache.cache-names=foo,bar
11 | spring.cache.guava.spec=maximumSize=500,expireAfterAccess=600s
12 | ```
13 | 此外,如果定义`com.google.common.cache.CacheLoader` bean,它会自动关联到`GuavaCacheManager`。由于该`CacheLoader`将关联该缓存管理器管理的所有缓存,它必须定义为`CacheLoader