package ee.esutoniagodesu; import ee.esutoniagodesu.config.Constants; import ee.esutoniagodesu.config.Profiles; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.SpringApplication; import org.springframework.boot.actuate.autoconfigure.*; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration; import org.springframework.boot.autoconfigure.dao.PersistenceExceptionTranslationAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration; import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; import org.springframework.boot.autoconfigure.web.MultipartAutoConfiguration; import org.springframework.boot.autoconfigure.websocket.WebSocketAutoConfiguration; import org.springframework.context.annotation.ComponentScan; import org.springframework.core.env.Environment; import org.springframework.core.env.SimpleCommandLinePropertySource; import javax.annotation.PostConstruct; import javax.inject.Inject; import java.io.IOException; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Arrays; import java.util.Collection; @EnableAutoConfiguration(exclude = { AuditAutoConfiguration.class, CacheAutoConfiguration.class, DataSourceAutoConfiguration.class, DataSourcePoolMetadataProvidersConfiguration.class, EndpointWebMvcHypermediaManagementContextConfiguration.class, EndpointWebMvcManagementContextConfiguration.class, //ErrorMvcAutoConfiguration.class, HealthIndicatorAutoConfiguration.class, MetricExportAutoConfiguration.class, MetricFilterAutoConfiguration.class, MetricRepositoryAutoConfiguration.class, MultipartAutoConfiguration.class, PersistenceExceptionTranslationAutoConfiguration.class, PublicMetricsAutoConfiguration.class, TraceRepositoryAutoConfiguration.class, TraceWebFilterAutoConfiguration.class, WebSocketAutoConfiguration.class }) @ComponentScan public class Application { private static final Logger log = LoggerFactory.getLogger(Application.class); @Inject private Environment env; /** * Initializes egd. * Spring profiles can be configured with a program arguments --spring.profiles.active=your-active-profile */ @PostConstruct public void initApplication() throws IOException { if (env.getActiveProfiles().length < 1) { log.error("No Spring profile configured, running with default configuration"); } else { log.info("Running with Spring profile(s) : {}", Arrays.toString(env.getActiveProfiles())); Collection activeProfiles = Arrays.asList(env.getActiveProfiles()); if (activeProfiles.contains("dev") && activeProfiles.contains("prod")) { log.error("You have misconfigured your application! " + "It should not run with both the 'dev' and 'prod' profiles at the same time."); } } } /** * Main method, used to run the application. */ public static void main(String[] args) throws UnknownHostException { SpringApplication app = new SpringApplication(Application.class); SimpleCommandLinePropertySource source = new SimpleCommandLinePropertySource(args); addDefaultProfile(app, source); Environment env = app.run(args).getEnvironment(); String protocol = env.containsProperty("server.ssl.key-store") ? "https" : "http"; log.info("Access URLs:\n----------------------------------------------------------\n\t" + "Local: \t\t{}://localhost:{}{}\n\t" + "External: \t{}://{}:{}{}\n----------------------------------------------------------", protocol, env.getProperty("server.port"), env.getProperty("server.contextPath", ""), protocol, InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"), env.getProperty("server.contextPath", "")); } /** * If no profile has been configured, set by default the "dev" profile. */ private static void addDefaultProfile(SpringApplication app, SimpleCommandLinePropertySource source) { if (!source.containsProperty("spring.profiles.active") && !System.getenv().containsKey("SPRING_PROFILES_ACTIVE")) { app.setAdditionalProfiles(Profiles.SPRING_PROFILE_DEV); } } }