Search in sources :

Example 91 with Environment

use of org.springframework.core.env.Environment in project jhipster-sample-app-websocket by jhipster.

the class JhipsterWebsocketSampleApplicationApp method main.

/**
 * Main method, used to run the application.
 *
 * @param args the command line arguments
 */
public static void main(String[] args) {
    SpringApplication app = new SpringApplication(JhipsterWebsocketSampleApplicationApp.class);
    DefaultProfileUtil.addDefaultProfile(app);
    Environment env = app.run(args).getEnvironment();
    String protocol = "http";
    if (env.getProperty("server.ssl.key-store") != null) {
        protocol = "https";
    }
    String hostAddress = "localhost";
    try {
        hostAddress = InetAddress.getLocalHost().getHostAddress();
    } catch (Exception e) {
        log.warn("The host name could not be determined, using `localhost` as fallback");
    }
    log.info("\n----------------------------------------------------------\n\t" + "Application '{}' is running! Access URLs:\n\t" + "Local: \t\t{}://localhost:{}\n\t" + "External: \t{}://{}:{}\n\t" + "Profile(s): \t{}\n----------------------------------------------------------", env.getProperty("spring.application.name"), protocol, env.getProperty("server.port"), protocol, hostAddress, env.getProperty("server.port"), env.getActiveProfiles());
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) Environment(org.springframework.core.env.Environment)

Example 92 with Environment

use of org.springframework.core.env.Environment in project jhipster-sample-app-oauth2 by jhipster.

the class JhipsterOauth2SampleApplicationApp method main.

/**
 * Main method, used to run the application.
 *
 * @param args the command line arguments
 */
public static void main(String[] args) {
    SpringApplication app = new SpringApplication(JhipsterOauth2SampleApplicationApp.class);
    DefaultProfileUtil.addDefaultProfile(app);
    Environment env = app.run(args).getEnvironment();
    String protocol = "http";
    if (env.getProperty("server.ssl.key-store") != null) {
        protocol = "https";
    }
    String hostAddress = "localhost";
    try {
        hostAddress = InetAddress.getLocalHost().getHostAddress();
    } catch (Exception e) {
        log.warn("The host name could not be determined, using `localhost` as fallback");
    }
    log.info("\n----------------------------------------------------------\n\t" + "Application '{}' is running! Access URLs:\n\t" + "Local: \t\t{}://localhost:{}\n\t" + "External: \t{}://{}:{}\n\t" + "Profile(s): \t{}\n----------------------------------------------------------", env.getProperty("spring.application.name"), protocol, env.getProperty("server.port"), protocol, hostAddress, env.getProperty("server.port"), env.getActiveProfiles());
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) Environment(org.springframework.core.env.Environment)

Example 93 with Environment

use of org.springframework.core.env.Environment in project hello-world by haoziapple.

the class JhApp method main.

/**
 * Main method, used to run the application.
 *
 * @param args the command line arguments
 * @throws UnknownHostException if the local host name could not be resolved into an address
 */
public static void main(String[] args) throws UnknownHostException {
    SpringApplication app = new SpringApplication(JhApp.class);
    DefaultProfileUtil.addDefaultProfile(app);
    Environment env = app.run(args).getEnvironment();
    String protocol = "http";
    if (env.getProperty("server.ssl.key-store") != null) {
        protocol = "https";
    }
    log.info("\n----------------------------------------------------------\n\t" + "Application '{}' is running! Access URLs:\n\t" + "Local: \t\t{}://localhost:{}\n\t" + "External: \t{}://{}:{}\n\t" + "Profile(s): \t{}\n----------------------------------------------------------", env.getProperty("spring.application.name"), protocol, env.getProperty("server.port"), protocol, InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"), env.getActiveProfiles());
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) Environment(org.springframework.core.env.Environment)

Example 94 with Environment

use of org.springframework.core.env.Environment in project jhipster-registry by jhipster.

the class ProfileInfoResourceTest method setup.

@Before
public void setup() {
    Environment env = Mockito.mock(Environment.class);
    JHipsterProperties prop = Mockito.mock(JHipsterProperties.class);
    JHipsterProperties.Ribbon ribbon = Mockito.mock(JHipsterProperties.Ribbon.class);
    ProfileInfoResource profileInfoResource = new ProfileInfoResource(env, prop);
    this.mock = MockMvcBuilders.standaloneSetup(profileInfoResource).build();
    Mockito.when(env.getActiveProfiles()).thenReturn(profiles);
    Mockito.when(prop.getRibbon()).thenReturn(ribbon);
}
Also used : JHipsterProperties(io.github.jhipster.config.JHipsterProperties) Environment(org.springframework.core.env.Environment) Before(org.junit.Before)

Example 95 with Environment

use of org.springframework.core.env.Environment in project herd by FINRAOS.

the class AppSpringModuleConfig method log4jConfigurer.

/**
 * The Log4J overridable configurer that will handle our Log4J initialization for the herd application.
 * <p/>
 * IMPORTANT: Ensure this method is static since the returned Log4jOverridableConfigurer is a bean factory post processor (BFPP). If it weren't static,
 * autowiring and injection on this @Configuration class won't work due to lifecycle issues. See "Bootstrapping" comment in @Bean annotation for more
 * details.
 *
 * @return the Log4J overridable configurer.
 */
@Bean
public static Log4jOverridableConfigurer log4jConfigurer() {
    // Access the environment using the application context holder since we're in a static method that doesn't have access to the environment in any
    // other way.
    Environment environment = ApplicationContextHolder.getApplicationContext().getEnvironment();
    // Create the Log4J configurer.
    Log4jOverridableConfigurer log4jConfigurer = new Log4jOverridableConfigurer();
    // This is the primary database override location (if present). An entry needs to be present in the database at application startup for this
    // configuration to be used.
    log4jConfigurer.setDataSource(DaoSpringModuleConfig.getHerdDataSource());
    log4jConfigurer.setTableName(ConfigurationEntity.TABLE_NAME);
    log4jConfigurer.setSelectColumn(ConfigurationEntity.COLUMN_VALUE_CLOB);
    log4jConfigurer.setWhereColumn(ConfigurationEntity.COLUMN_KEY);
    log4jConfigurer.setWhereValue(ConfigurationValue.LOG4J_OVERRIDE_CONFIGURATION.getKey());
    // This is the secondary override location (if present and if the primary location isn't present). This resource needs to be present at application
    // startup for this configuration to be used.
    log4jConfigurer.setOverrideResourceLocation(ConfigurationHelper.getProperty(ConfigurationValue.LOG4J_OVERRIDE_RESOURCE_LOCATION, environment));
    // This is the default fallback location which is bundled in the WAR and should always be present in case the override locations aren't present.
    // Note that the herd-log4j.xml file must be in the herd-war project so it is accessible on the classpath as a file. Placing it within another
    // project's JAR will result in the resource not being found as a "file".
    log4jConfigurer.setDefaultResourceLocation("classpath:herd-log4j.xml");
    // Return the Log4J configurer.
    return log4jConfigurer;
}
Also used : Log4jOverridableConfigurer(org.finra.herd.dao.Log4jOverridableConfigurer) Environment(org.springframework.core.env.Environment) Bean(org.springframework.context.annotation.Bean)

Aggregations

Environment (org.springframework.core.env.Environment)161 Test (org.junit.jupiter.api.Test)68 StandardEnvironment (org.springframework.core.env.StandardEnvironment)30 EnvironmentVariableUtility (com.synopsys.integration.alert.environment.EnvironmentVariableUtility)26 MockEnvironment (org.springframework.mock.env.MockEnvironment)24 SpringApplication (org.springframework.boot.SpringApplication)21 EnvironmentProcessingResult (com.synopsys.integration.alert.environment.EnvironmentProcessingResult)19 EnvironmentVariableHandler (com.synopsys.integration.alert.environment.EnvironmentVariableHandler)19 EnvironmentVariableHandlerFactory (com.synopsys.integration.alert.environment.EnvironmentVariableHandlerFactory)19 HashMap (java.util.HashMap)13 ResourceLoader (org.springframework.core.io.ResourceLoader)13 Collectors (java.util.stream.Collectors)11 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)10 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)9 MutablePropertySources (org.springframework.core.env.MutablePropertySources)8 AlertConstants (com.synopsys.integration.alert.api.common.model.AlertConstants)7 ChannelKeys (com.synopsys.integration.alert.descriptor.api.model.ChannelKeys)7 EnvironmentVariableMockingUtil (com.synopsys.integration.alert.test.common.EnvironmentVariableMockingUtil)7 Map (java.util.Map)7 Predicate (java.util.function.Predicate)7