首页  

spring注解之@Value     所属分类 spring 浏览量 1051
${ property : default_value } 
注入配置文件属性值

#{ beanName.property? :default_value } 
注入 SpEL表达式对应的值


@Value("${app.name}")
private String name;

@Value("${app.info:default-info}")
private String info;


@Value("#{bean1.name2}")
private String name;


@ComponentScan
@Configuration
@PropertySource(value={"classpath:application.properties","classpath:a.config"})
public class Config1{
	@Bean
    public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
        return new PropertySourcesPlaceholderConfigurer();
    }	
}

注意一定要 配置  PropertySourcesPlaceholderConfigurer  bean !!! 
否则不会做替换


完整代码
https://gitee.com/dyyx/hellocode/tree/master/project/springtest/src/main/java/dyyx/value

上一篇     下一篇
spring组件扫描

spring实战之javaconfig

jar包冲突的处理套路

金融圈饭局老司机火眼金睛识人

云原生应用12要素

java日志框架冲突介绍