Could not resolve placeholder 'cupszie' in value "cupsize: ${cupszie},age: ${age}"
報錯如下:
Error creating bean with name 'helloController': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'cupszie' in value "cupsize: ${cupszie},age: ${age}"
代碼如下:
application.yml代碼
server:
?port: 8081
?context-path: /girl
cupsize: B
age: 20
content: "cupsize: ${cupszie},age: ${age}"
HelloController.class代碼
@RestController
public class HelloController {
? ?@Value("${cupsize}")
? ?private String cupsize;
? ?@Value("${age}")
? ?private Integer age;
? ?@Value("${content}")
? ?private String content;
? ?@RequestMapping(value = "/hello",method = RequestMethod.GET)
? ?public String say(){
? ? ? ?return content;
? ?}
}
代碼跟老師的一樣,請教老師這是為什么呢
2018-08-01
server:
? port: 8080
? servlet:
? ? context-path: /girl1
girl:?
? cupSzie: B
? age: 12
我的這個是在同一水平,為啥還是獲取不到
2018-04-26
報錯
2018-04-21
保持sever同一水平
比如:
sever:
port: 8080
cupSize: B
? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
2018-02-27
有毒有毒
2017-12-09
2017-10-28
還真是不能有空格。。。。
2017-10-26
改為這樣就可以了content: "cupSize: ${server.cupSize}, age: ${server.age}"
2017-10-13
樓主,在配置文件那里是不能留有空格的,明顯的你port下面的
server:
?????????port: 8081
?????????context-path: /girl
????????cupsize: B
????????age:?
屬性是有空格的,所以需要加server.cupSize,要跟server一樣哦,沒有縮進,如下:
server:
?port: 8081
context-path: /girl
cupsize: B
?age:
2017-10-05
我的也是這個問題 只要yml文件格式寫好了在controller中加上server.context就可以了獲取了 樓主可以試試
2017-09-19
樓主解決了沒有