寒假累死累活,勉勉强强搞定了黑马的ssm
就理所应当的想着顺便搞定一下springboot,就看上了尚硅谷的springboot核心,本来一切顺风顺水,没成想在第10P就献上了第一个bug。
在这里插入图片描述从yaml配置文件获取pojo值,老夫不负所望呵。我看了好几遍视频和好多blog的。
上代码
pojo代码就不给了,大概就是如下的yaml所示,
person:
lastName: zhangsan
age: 18
boss: false
birrth: 2020/3/17
maps: {k1:v1,k2:v2}
lists:
- lisi
- zhaoliu
dog:
name: 小狗
age: 2
上maven依赖了
<dependency> //文件处理器
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency> //@SpringBootTest
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<version>2.2.4.RELEASE</version>
</dependency>
<dependency>//@RunWith和@Test
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>//SpringRunner.class
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.2.3.RELEASE</version>
</dependency>
package com.atguigu;
import com.atguigu.bean.Person;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringBoot02ConfigApplicationTests {
@Autowired
Person person;
@Test
public void contextLoads(){
System.out.println(person);
}
}
好了,重头戏来了,怎么解决Failed to load ApplicationContext呢,加个构造方法,完事了
那个birth为什么是空值呢?当然是我打错了,并且懒得改。