2015-02-08 71 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

相關問題