通过@Value注解将application.yml中的值映射到一个Spring管理的Bean的字段上。

@Value只能注入普通变量

1
2
3
4
5
6
//队列的名称(自动注入)
@Value("${xuecheng.mq.queue}")
public String queue_cms_postpage_name; //routingKey 即站点Id

@Value("${xuecheng.mq.routinKey}")
public String routingKey;

以上代码会导致SpringBoot启动时报错:Could not resolve placeholder ‘XXX.XXX‘ in value