Below
statements return all the active profiles.
Environment
environment = applicationContext.getBean(Environment.class);
for
(final String profileName : environment.getActiveProfiles()) {
System.out.println("Currently
active profile : " + profileName);
}
Find
the below working application.
Application.java
package com.sample.myApp; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.env.Environment; @SpringBootApplication public class Application { public static void main(String[] args) { ConfigurableApplicationContext applicationContext = SpringApplication.run(Application.class, args); Environment environment = applicationContext.getBean(Environment.class); for (final String profileName : environment.getActiveProfiles()) { System.out.println("Currently active profile : " + profileName); } applicationContext.close(); } }
No comments:
Post a Comment