@PropertySource 和 @Value
@Component
@PropertySource("classpath:KdNiao.properties")
@Data
public class KdNiaoConfig {
@Value("${EBusinessID}")
private String EBusinessID;
@Value("${AppKey}")
private String AppKey;
}
- 在类上使用 @PropertySource 注解,value 填写properties路径
- 在属性上使用@Value注解,value填写properties对应属性的key
- @Component可以将类注入到要使用的位置,new出来的不生效。
- 使用@Component的类要被@ComponentScan扫描到,才可注入成功(全注解写法)