2 * In Samsung Ukraine R&D Center (SRK under a contract between)
3 * LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
4 * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
6 package com.samsung.samserver;
8 import com.samsung.samserver.config.ApplicationProperties;
9 import com.samsung.samserver.config.DefaultProfileUtil;
11 import io.github.jhipster.config.JHipsterConstants;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
15 import org.springframework.beans.factory.annotation.Qualifier;
16 import org.springframework.boot.SpringApplication;
17 import org.springframework.boot.actuate.autoconfigure.*;
18 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
19 import org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties;
20 import org.springframework.boot.context.properties.EnableConfigurationProperties;
21 import org.springframework.context.annotation.ComponentScan;
22 import org.springframework.core.env.Environment;
23 import springfox.documentation.builders.PathSelectors;
24 import springfox.documentation.spring.web.plugins.Docket;
26 import javax.annotation.PostConstruct;
27 import java.net.InetAddress;
28 import java.net.UnknownHostException;
29 import java.util.Arrays;
30 import java.util.Collection;
33 @EnableAutoConfiguration(exclude = {MetricFilterAutoConfiguration.class, MetricRepositoryAutoConfiguration.class})
34 @EnableConfigurationProperties({LiquibaseProperties.class, ApplicationProperties.class})
35 public class SamserverApp {
37 private static final Logger log = LoggerFactory.getLogger(SamserverApp.class);
39 private final Environment env;
41 private final Docket managementDocket;
42 private final Docket apiDocket;
44 public SamserverApp(Environment env,
45 @Qualifier("swaggerSpringfoxManagementDocket")Docket managementDocket,
46 @Qualifier("swaggerSpringfoxApiDocket") Docket apiDocket) {
48 this.managementDocket = managementDocket;
49 this.apiDocket = apiDocket;
53 * Initializes samserver.
55 * Spring profiles can be configured with a program arguments --spring.profiles.active=your-active-profile
57 * You can find more information on how profiles work with JHipster on <a href="http://www.jhipster.tech/profiles/">http://www.jhipster.tech/profiles/</a>.
60 public void initApplication() {
61 Collection<String> activeProfiles = Arrays.asList(env.getActiveProfiles());
62 if (activeProfiles.contains(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT) && activeProfiles.contains(JHipsterConstants.SPRING_PROFILE_PRODUCTION)) {
63 log.error("You have misconfigured your application! It should not run " +
64 "with both the 'dev' and 'prod' profiles at the same time.");
66 if (activeProfiles.contains(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT) && activeProfiles.contains(JHipsterConstants.SPRING_PROFILE_CLOUD)) {
67 log.error("You have misconfigured your application! It should not " +
68 "run with both the 'dev' and 'cloud' profiles at the same time.");
70 managementDocket.enable(false);
71 apiDocket.select().paths(PathSelectors.regex("/api/device-service.*")).build();
75 * Main method, used to run the application.
77 * @param args the command line arguments
78 * @throws UnknownHostException if the local host name could not be resolved into an address
80 public static void main(String[] args) throws UnknownHostException {
81 SpringApplication app = new SpringApplication(SamserverApp.class);
82 DefaultProfileUtil.addDefaultProfile(app);
83 Environment env = app.run(args).getEnvironment();
84 String protocol = "http";
85 if (env.getProperty("server.ssl.key-store") != null) {
88 log.info("\n----------------------------------------------------------\n\t" +
89 "Application '{}' is running! Access URLs:\n\t" +
90 "Local: \t\t{}://localhost:{}\n\t" +
91 "External: \t{}://{}:{}\n\t" +
92 "Profile(s): \t{}\n----------------------------------------------------------",
93 env.getProperty("spring.application.name"),
95 env.getProperty("server.port"),
97 InetAddress.getLocalHost().getHostAddress(),
98 env.getProperty("server.port"),
99 env.getActiveProfiles());