第一次是用這個(gè)IDE,根據(jù)提示導(dǎo)了一個(gè)依賴,但是結(jié)果打印出來(lái)是null,也沒有報(bào)錯(cuò),求老師指導(dǎo)!
是這個(gè)依賴
<dependency> ???<groupId>org.springframework.boot</groupId> ???<artifactId>spring-boot-configuration-processor</artifactId> ???<optional>true</optional> </dependency>
然后,打印結(jié)果截圖:
Hello!?SpringBoot?!?nullnull
這個(gè)是源代碼:
@Component
@ConfigurationProperties(prefix = "girl")
public class GirlProperties {
? ?private String cupSize;
? ?private Integer age;
以下是get、set方法
然后還有控制類的代碼:
@RestController
public class ?helloController {
? ?@Autowired
? ?private GirlProperties girlProperties;
? ?@RequestMapping(value = "/hello",method = RequestMethod.GET )
? ?public String say(){
? ? ? ?return "Hello! SpringBoot ! "+girlProperties.getCupSize()+girlProperties.getAge();
? ?}
2017-08-15
同樣null
2017-06-06
看一下配置文件和類中對(duì)應(yīng)的字段一定要保持一致,
2017-04-30
我的也是null 找不到原因
2017-03-25
看一下配置文件屬性名稱和定義的類的字段名稱是否一致