1.命令行参数配置java
Spring Boot是基于jar包运行的,打成jar包的程序能够直接经过spring
java -jar export.jar
能够经过命令修改应用服务器端口安全
java -jar export.jar --server.port=9000
2.常规属性注入服务器
常规Spring环境下,可以使用@ProperySource指定properties文件位置,而后经过@Value注入值。app
在Spring Boot中只须要在application.properties定义属性,直接使用@Value注入便可this
3.类型安全的配置spa
每一个属性都用@Value注入则略显麻烦,Spring Boot提供了基于类型安全的配置方式,经过@ConfigurationProperties将properties属性和一个Bean及其属性关联,实现类型安全。.net
// application.properties book.name=Spring Boot book.author=Spring
经过@ConfigurationProperties加载properties文件内的配置,经过prefix属性指定properties的配置前缀,经过locations可执行properties文件位置。命令行
类型安全的Bean code
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; /** * @author Kevin * @description * @date 2016/7/6 */ @Component // application.properties默认加载 因此不须要指定locations // @ConfigurationProperties(prefix = "book",locations={"classpath:author.properties"}) @ConfigurationProperties(prefix = "book") public class Book { private String name; private String author; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAuthor() { return author; } public void setAuthor(String author) { this.author = author; } }
4.Profile配置
Profile是Spring用来针对不一样环境对不一样配置提供的支持。application-prod.properties(生产环境)、application-dev.properties(开发环境)。经过在application.properties中设置
spring.profiles.active=prod
指定加载不一样的profile配置文件