8. Spring 使用外部属性文件 注解

8.1 主要清单 @PropertySource 和 Environment

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;

@Configuration
@PropertySource("classpath:/app.properties")
public class ExpressiveConfig {
    @Autowired
    private Environment environment;

    @Bean
    public A a(){
        new A(environment.getProperty("a.name"));
    }
}

 

posted @ 2018-05-22 15:00  侯光辉  阅读(149)  评论(0编辑  收藏  举报