@value 注解获取属性文件中的值

一、属性文件 db.properties

name=jack

二、配置文件 applicationContext.xml

<!-- 加载配置文件,该节点只能存在一个,所以用 * ,加载所有属性文件 -->
<context:property-placeholder location="classpath:conf/*.properties" />

  或者@PropertySource

//@PropertySource:读取属性文件
@PropertySource(value={"classpath:conf/*.properties"})
@Configuration
public class ConfigOfLifeCycle {
    
    @Bean
    public Student student(){
        return new Student();
    }
}

三、java 代码

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

 

posted @ 2018-03-25 15:38  方方方方方方  阅读(740)  评论(0编辑  收藏  举报