Spring Boot 外部化配置简介

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spring Boot 外部化配置简介相关的知识,希望对你有一定的参考价值。

参考技术A Spring Boot提供properties文件、YAML文件、环境变量(environment variables)和命令行参数的方式进行外部化配置,可以在不同的环境,使用不同的配置信息。
应用可以通过@Value注入到bean,也可以通过@ConfigurationProperties进行对象的绑定配置。

Spring Boot提供的默认通配符路径(wildcard location)在jar包路径的config/*/目录下。
可以通过指定spring.config.additional-location和spring.config.location来修改

1Spring Boot简介

什么是SpringBoot

Spring Boot是Spring社区发布的一个开源项目,旨在帮助开发者快速并且更简单的构建项目。大多数SpringBoot项目只需要很少的配置文件。

SpringBoot特性

  • 创建独立的Spring项目
  • 内置Tomcat和Jetty容器
  • 提供一个starter POMs来简化Maven配置
  • 提供了一系列大型项目中常见的非功能性特性,如安全、指标,健康检测、外部配置等
  • 完全没有代码生成和xml配置文件

SpringBoot运行环境

Spring Boot最新版可以运行在Java6+的环境下,但是Spring官方建议使用Java8。

Servlet 容器

Name Servlet Version Java Version
Tomcat 8 3.1 Java 7+
Tomcat 7 3.0 Java 6+
Jetty 9 3.1 Java 7+
Jetty 8 3.0 Java 6+
Undertow 1.1 3.1 Java 7+

SpringBoot支持哪些应用

使用SpringBoot可以快速创建普通Java项目和Web项目,以及其他项目。

Spring Boot application starters

Name Description
spring-boot-starter The core Spring Boot starter, including auto-configuration support, logging and YAML.
spring-boot-starter-actuator Production ready features to help you monitor and manage your application.
spring-boot-starter-amqp Support for the “Advanced Message Queuing Protocol” via spring-rabbit.
spring-boot-starter-aop Support for aspect-oriented programming including spring-aop and AspectJ.
spring-boot-starter-artemis Support for “Java Message Service API” via Apache Artemis.
spring-boot-starter-batch Support for “Spring Batch” including HSQLDB database.
spring-boot-starter-cache Support for Spring’s Cache abstraction.
spring-boot-starter-cloud-connectors Support for “Spring Cloud Connectors” which simplifies connecting to services in cloud platforms like Cloud Foundry and Heroku.
spring-boot-starter-data-elasticsearch Support for the Elasticsearch search and analytics engine including spring-data-elasticsearch.
spring-boot-starter-data-gemfire Support for the GemFire distributed data store including spring-data-gemfire.
spring-boot-starter-data-jpa Support for the “Java Persistence API” including spring-data-jpa, spring-orm and Hibernate.
spring-boot-starter-data-mongodb Support for the MongoDB NoSQL Database, including spring-data-mongodb.
spring-boot-starter-data-redis Support for the REDIS key-value data store, including spring-data-redis.
spring-boot-starter-data-rest Support for exposing Spring Data repositories over REST via spring-data-rest-webmvc.
spring-boot-starter-data-solr Support for the Apache Solr search platform, including spring-data-solr.
spring-boot-starter-freemarker Support for the FreeMarker templating engine.
spring-boot-starter-groovy-templates Support for the Groovy templating engine.
spring-boot-starter-hateoas Support for HATEOAS-based RESTful services via spring-hateoas.
spring-boot-starter-hornetq Support for “Java Message Service API” via HornetQ.
spring-boot-starter-integration Support for common spring-integration modules.
spring-boot-starter-jdbc Support for JDBC databases.
spring-boot-starter-jersey Support for the Jersey RESTful Web Services framework.
spring-boot-starter-jta-atomikos Support for JTA distributed transactions via Atomikos.
spring-boot-starter-jta-bitronix Support for JTA distributed transactions via Bitronix.
spring-boot-starter-mail Support for javax.mail.
spring-boot-starter-mobile Support for spring-mobile.
spring-boot-starter-mustache Support for the Mustache templating engine.
spring-boot-starter-security Support for spring-security.
spring-boot-starter-social-facebook Support for spring-social-facebook.
spring-boot-starter-social-linkedin Support for spring-social-linkedin.
spring-boot-starter-social-twitter Support for spring-social-twitter.
spring-boot-starter-test Support for common test dependencies, including JUnit, Hamcrest and Mockito along with the spring-testmodule.
spring-boot-starter-thymeleaf Support for the Thymeleaf templating engine, including integration with Spring.
spring-boot-starter-velocity Support for the Velocity templating engine.
spring-boot-starter-web Support for full-stack web development, including Tomcat and spring-webmvc.
spring-boot-starter-websocket Support for WebSocket development.
spring-boot-starter-ws Support for Spring Web Services.

以上是关于Spring Boot 外部化配置简介的主要内容,如果未能解决你的问题,请参考以下文章

Spring Boot

Spring Boot学习之一Spring Boot简介

Spring Boot 简介

spring boot项目application.properties多环境配置文件jar包外部配置文件

Spring Boot @ConfigurationProperties使用指导

Spring/Spring Boot的外部化配置