2015-02-08 74 views

回答

103

它并不重要是你的应用程序引导或只是原始的春天。只需将Environment注入到bean中即可。

@Autowired 
private Environment environment; 
.... 

this.environment.getActiveProfiles(); 
+0

谢谢。你将如何为不同的配置文件创建不同的属性文件? – rayman 2015-02-08 14:15:58

+3

这绝对是单独的SO问题。但是,您可以查看引导文档:http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config- profile-specific-properties – 2015-02-08 14:36:04

+0

'org.springframework.core.env.Environment' – 2017-12-21 15:01:19

相关问题