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;