Spring无配置使用properties文件

利用@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;

 

posted @ 2014-01-26 11:01  王 庆  阅读(464)  评论(0编辑  收藏  举报