application-dev.yml
server:
servlet:
context-path: /
port: 8080
boy:
name: dulong
age : 20
application-prod.yml
server:
servlet:
context-path: /
port: 8080
boy:
name: dulong
age : 20
在application.yml中配置
spring:
profiles:
active: prod // prod文件报错 但是指定激活dev却可以正常获取值
error:
Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'boy.name' in value "${boy.name}"
public class HelloController {
@Autowired
private Boy boy;
@RequestMapping(value = "/hello",method = RequestMethod.GET)
public String hello() {
return "注入组件方式获取值:name-"+boy.getName()+ " age-"+boy.getAge();
}
}