springboot学习第三天之异步调用、自定义参数、修改端口号、yml使用

1.springboot中默认实现异步

单线程,结果1342
 多线程异步,使用 @Async注解,结果1234,在主程序运行类上添加 @EnableAsync注解,开启异步
2.自定义参数
配置文件值:在applications.properties中添加
配置文件值;
@Value("$(name)")//通过value注解获得值
private String name;
3.多环境配置
什么是多环境配置?www.baidu.com===>prd.baidu.com

企业中:
test--本地开发环境
sit----测试环境
pre---预生产环境
prd--生产环境

applications.properties
spring.profiles.active=pre// 找applications-pre以pre为后缀的properties文件
applications-test.properties
name=test. baidu.com
applications-sit.properties
name=sit. baidu.com
applications-pre.properties
name=pre. baidu.com
4.修改端口号
//spring默认端口号8080
server.port=8888
server.context-path=/it-edu
5.yml文件使用
建立application.yml文件,每一个:后面需要 加空格,有自动提示
yml文件和application.properties文件可以并存一起读
好处:减少字符数,增加易读性
server:
  port:8088
  context-path: /www.com

猜你喜欢

转载自blog.csdn.net/Study_Live_Sun/article/details/80378132