Spring无配置使用properties文件

来源:互联网 发布:淘宝2楼 一千零一夜 编辑:程序博客网 时间:2024/05/29 04:47

利用@PropertySource注解加载

@Configuration@ComponentScan(basePackages="*")@PropertySource({"classpath:config.properties"})//@Import(DataSourceConfig.class)public class DefaultAppConfig {    @Bean    public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {        return new PropertySourcesPlaceholderConfigurer();    }}

利用@Value使用

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

 

0 0