快速上手
1、
2、配置包名、路径和环境
3、选择服务 版本选择2.7.8
注意报错
版本不适配的解决办法:检查下面四个设置 是否和本地的JDK版本一致
求解答maven报错 类文件具有错误的版本 55.0, 应为 52.0 请删除该文件或确保该文件位于正确的类路径子
解决方式:在创建的第三步选择低版本
Spring boot启动页面的彩蛋
————————————————————————————————————————————————————————————————————
// _ooOoo_ //
// o8888888o //
// 88" . "88 //
// (| ^_^ |) //
// O\ = /O //
// ____/`---'\____ //
// .' \\| |// `. //
// / \\||| : |||// \ //
// / _||||| -:- |||||- \ //
// | | \\\ - /// | | //
// | \_| ''\---/'' | | //
// \ .-\__ `-` ___/-. / //
// ___`. .' /--.--\ `. . ___ //
// ."" '< `.___\_<|>_/___.' >'"". //
// | | : `- \`.;`\ _ /`;.`/ - ` : | | //
// \ \ `-. \_ __\ /__ _/ .-` / / //
// ========`-.____`-.___\_____/___.-`____.-'======== //
// `=---=' //
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ //
// 佛祖保佑 永不宕机 永无BUG //
————————————————————————————————————————————————————————————————————
yaml配置
对于preporties的优势:
配置简单 结构清晰 可以给对象赋值
同时yaml配置多环境简单 只需要一个yaml文件
而properties需要多个文件
配置文件存放的位置:1-4 优先级一直减少 优先读取file:./config/
yaml语法结构
注意 当变量名高亮时说明语法生效 否则是没有加空格
普通键值对
key: value 冒号后面有个空格
对象
person:
name: huangyi
age: 24
happy: false
birth: 1999/03/04
maps: {1: asd,2: qwe,3: zxc}
lists:
- code
- basketball
- girls
数组
animal:
- dog
- cat
- pig
YAML如何注入到对象属性中
总体结构:
编写YAML
person:
name: huangyi
age: 24
happy: false
birth: 1999/03/04
maps: {1: asd,2: qwe,3: zxc}
lists:
- code
- basketball
- girls
编写实体类
关键注释:@ConfigurationProperties(prefix = "person")
其中prefixde值要与yaml中的一致
@Component
@ConfigurationProperties(prefix = "person")
public class Person {
private String name;
private Integer age;
private Boolean happy;
private Date birth;
private Map<String,Object> maps;
private List<Object> lists;
public Person() {
}
public Person(String name, Integer age, Boolean happy, Date birth, Map<String, Object> maps, List<Object> lists) {
this.name = name;
this.age = age;
this.happy = happy;
this.birth = birth;
this.maps = maps;
this.lists = lists;
}
}
开始测试赋值
@SpringBootTest
class ShowApplicationTests {
@Autowired
private Person person;
@Test
void contextLoads() {
System.out.printf(person.toString());
}
//省略下面getter setter toStrui
}
YAML多环境配置
关键 profiles active 和---
server:
port: 1299
spring:
profiles:
active: test
---
server:
port: 11299
spring:
profiles: test
---
spring:
profiles: dev