您可以
@PropertySource用来将配置外部化为属性文件。有很多方法可以获取属性:
1.分配通过使用属性值的字段@Value
与PropertySourcesPlaceholderConfigurer
刚毅${}的@Value
:
@Configuration@PropertySource("file:config.properties")public class ApplicationConfiguration { @Value("${gMapReportUrl}") private String gMapReportUrl; @Bean public static PropertySourcesPlaceholderConfigurer propertyConfigInDev() { return new PropertySourcesPlaceholderConfigurer(); }}2.通过使用获取属性值Environment
:
@Configuration@PropertySource("file:config.properties")public class ApplicationConfiguration { @Autowired private Environment env; public void foo() { env.getProperty("gMapReportUrl"); }}希望这可以帮助



