Search in sources :

Example 86 with Environment

use of org.springframework.core.env.Environment in project rdbcache by rdbcache.

the class Application method main.

public static void main(String[] args) {
    if (args != null && args.length > 0) {
        for (int i = 0; i < args.length; i++) {
            if (args[i].equals("-v") || args[i].equals("--version")) {
                System.out.println("\n" + AppCtx.getVersionInfo().getFullInfo() + "\n");
                return;
            }
        }
    }
    SpringApplication app = new SpringApplication(Application.class);
    app.setBanner(new Banner() {

        @Override
        public void printBanner(Environment environment, Class<?> aClass, PrintStream printStream) {
            printStream.println("\n" + AppCtx.getVersionInfo().getFullInfo() + "\n");
        }
    });
    ConfigurableApplicationContext context = app.run(args);
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) PrintStream(java.io.PrintStream) Environment(org.springframework.core.env.Environment)

Example 87 with Environment

use of org.springframework.core.env.Environment in project nikita-noark5-core by HiOA-ABI.

the class N5CoreApp 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(final String... args) throws UnknownHostException {
    //SpringApplication app = new SpringApplication(N5CoreApp.class);
    //SimpleCommandLinePropertySource source = new SimpleCommandLinePropertySource(args);
    ConfigurableApplicationContext context = SpringApplication.run(CONFIGS, args);
    context.getBean(AfterApplicationStartup.class).afterApplicationStarts();
    Environment env = context.getEnvironment();
    String[] activeProfiles = env.getActiveProfiles();
    String profilesAsString = Arrays.toString(activeProfiles);
    logger.info("\n----------------------------------------------------------\n\t" + "Application '{}' is running! Access URLs:\n\t" + "Local: \t\t\thttp://localhost:{}\n\t" + "External: \t\thttp://{}:{}\n\t" + "contextPath: \thttp://{}:{}{} \n\t" + "Application is running with following profile(s): {} \n\t" + "\n----------------------------------------------------------", env.getProperty("spring.application.name"), env.getProperty("server.port"), InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"), InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"), env.getProperty("server.contextPath"), profilesAsString);
    String configServerStatus = env.getProperty("configserver.status");
    logger.info("\n----------------------------------------------------------\n\t" + "Config Server: \t{}\n----------------------------------------------------------", configServerStatus == null ? "Not found or not setup for this application" : configServerStatus);
    if (profilesAsString != null && profilesAsString.contains("de")) {
        logger.info("\n----------------------------------------------------------\n\t" + "Dev/demo mode: In-memory database ({}) in use. See http://localhost:8082 . Use following JDBC-string: jdbc:h2:mem:n5DemoDb/jdbc:h2:mem:n5DevDb" + "\n----------------------------------------------------------", env.getProperty("spring.jpa.database"));
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Environment(org.springframework.core.env.Environment)

Example 88 with Environment

use of org.springframework.core.env.Environment in project spring-data-commons by spring-projects.

the class CustomRepositoryImplementationDetector method findCandidateBeanDefinitions.

Set<BeanDefinition> findCandidateBeanDefinitions(String className, Iterable<String> basePackages, Iterable<TypeFilter> excludeFilters) {
    // Build pattern to lookup implementation class
    Pattern pattern = Pattern.compile(".*\\." + className);
    // Build classpath scanner and lookup bean definition
    ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false, environment);
    provider.setResourceLoader(resourceLoader);
    provider.setResourcePattern(String.format(CUSTOM_IMPLEMENTATION_RESOURCE_PATTERN, className));
    provider.setMetadataReaderFactory(metadataReaderFactory);
    provider.addIncludeFilter(new RegexPatternTypeFilter(pattern));
    excludeFilters.forEach(it -> provider.addExcludeFilter(it));
    return // 
    Streamable.of(basePackages).stream().flatMap(// 
    it -> provider.findCandidateComponents(it).stream()).collect(Collectors.toSet());
}
Also used : ResourceLoader(org.springframework.core.io.ResourceLoader) TypeFilter(org.springframework.core.type.filter.TypeFilter) NonNull(lombok.NonNull) Collection(java.util.Collection) ClassPathScanningCandidateComponentProvider(org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider) RegexPatternTypeFilter(org.springframework.core.type.filter.RegexPatternTypeFilter) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Set(java.util.Set) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) MetadataReaderFactory(org.springframework.core.type.classreading.MetadataReaderFactory) Environment(org.springframework.core.env.Environment) Streamable(org.springframework.data.util.Streamable) Optional(java.util.Optional) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) Pattern(java.util.regex.Pattern) Nullable(javax.annotation.Nullable) Assert(org.springframework.util.Assert) Pattern(java.util.regex.Pattern) ClassPathScanningCandidateComponentProvider(org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider) RegexPatternTypeFilter(org.springframework.core.type.filter.RegexPatternTypeFilter)

Example 89 with Environment

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

the class JhipsterElasticsearchSampleApplicationApp 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(JhipsterElasticsearchSampleApplicationApp.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 90 with Environment

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

the class JhipsterDtoSampleApplicationApp 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(JhipsterDtoSampleApplicationApp.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)

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