🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
### @Value用法 * 构造方法 ``` public DataSource(@Value("data.source") String source) { this.source = source; } ``` # 示例 * **@Value Examples** ``` #{expression?:default value} ``` Few examples : ``` @Value("#{systemProperties['mongodb.port'] ?: 27017}") private String mongodbPort; @Value("#{config['mongodb.url'] ?: '127.0.0.1'}") private String mongodbUrl; @Value("#{aBean.age ?: 21}") private int age; ``` P.S @Value has been available since Spring 3.0 * **@Value and Property Examples** ``` ${property:default value} ``` Few examples : ``` //@PropertySource("classpath:/config.properties}") //@Configuration @Value("${mongodb.url:127.0.0.1}") private String mongodbUrl; @Value("#{'${mongodb.url:172.0.0.1}'}") private String mongodbUrl; @Value("#{config['mongodb.url']?:'127.0.0.1'}") private String mongodbUrl; ```