1,自定义banner
-
打开网站:http://patorjk.com/software/taag/#p=display&h=3&v=3&f=4Max&t=lishan Spring Boot
-
拷贝生成的字符到一个文本文件中,并且将该文件命名为banner.txt
-
将banner.txt拷贝到项目的src/main/resources目录中
-
重新启动程序
2,自定义全局配置
SpringBoot项目使用一个全局的配置文件application.properties或者是application.yml,在resources目录下或者类路径下的/config下,一般我们放到resources下。
application.properties
- server.port=8888
application.yml(格式由空格判断子父级)
server:
port: 8888
更多的配置:
官方地址:
https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/
3,读取自定义配置
application.properties(内容)
my.name=张三
my.password=123456
TestController
@EnableAutoConfiguration(exclude= {RedisAutoConfiguration.class})
@Controller
public class TestController {
@Value("${my.name}") //取值方法
private String name;
@Value("${my.password}")
private String password;
@RequestMapping("/hello")
@ResponseBody
public String requestHello() {
return name+":"+password;
}
//入口
public static void main(String[] args) {
SpringApplication.run(TestController.class, args);
}
}
4,基于类型安全的配置
TestController
@EnableAutoConfiguration(exclude= {RedisAutoConfiguration.class}) //启用自动配置
@Controller
@ConfigurationProperties(prefix= "my") //通过次配置定义前缀和属性读取值
public class TestController {
private String name;
private String password;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@RequestMapping("/hello")
@ResponseBody
public String requestHello() {
return name+":"+password;
}
//入口
public static void main(String[] args) {
SpringApplication.run(TestController.class, args);
}
}
5,profile配置
profile是针对不同环境对不同的配置提供支持的,全局profile配置使用application-*.properties
通过在application.properties中设置spring.profiles.active=*来制定活动的profile
application.properties
- spring.profiles.active=dev
application-dev.properties
- server.port=8081