Search in sources :

Example 21 with Environment

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

the class JhipsterMongodbSampleApplicationApp 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(JhipsterMongodbSampleApplicationApp.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 22 with Environment

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

the class JhipsterHazelcastSampleApplicationApp 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(JhipsterHazelcastSampleApplicationApp.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 23 with Environment

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

the class RepositoryBeanDefinitionParser method parse.

/*
	 * (non-Javadoc)
	 * @see org.springframework.beans.factory.xml.BeanDefinitionParser#parse(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext)
	 */
@Nullable
public BeanDefinition parse(Element element, ParserContext parser) {
    XmlReaderContext readerContext = parser.getReaderContext();
    try {
        ResourceLoader resourceLoader = ConfigurationUtils.getRequiredResourceLoader(readerContext);
        Environment environment = readerContext.getEnvironment();
        BeanDefinitionRegistry registry = parser.getRegistry();
        XmlRepositoryConfigurationSource configSource = new XmlRepositoryConfigurationSource(element, parser, environment);
        RepositoryConfigurationDelegate delegate = new RepositoryConfigurationDelegate(configSource, resourceLoader, environment);
        RepositoryConfigurationUtils.exposeRegistration(extension, registry, configSource);
        for (BeanComponentDefinition definition : delegate.registerRepositoriesIn(registry, extension)) {
            readerContext.fireComponentRegistered(definition);
        }
    } catch (RuntimeException e) {
        handleError(e, element, readerContext);
    }
    return null;
}
Also used : ResourceLoader(org.springframework.core.io.ResourceLoader) XmlReaderContext(org.springframework.beans.factory.xml.XmlReaderContext) Environment(org.springframework.core.env.Environment) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) Nullable(org.springframework.lang.Nullable)

Example 24 with Environment

use of org.springframework.core.env.Environment in project spring-boot-starter-dubbo by teaey.

the class DubboConfigurationApplicationContextInitializer method initialize.

@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
    Environment env = applicationContext.getEnvironment();
    String scan = env.getProperty("spring.dubbo.scan");
    if (scan != null) {
        AnnotationBean scanner = BeanUtils.instantiate(AnnotationBean.class);
        scanner.setPackage(scan);
        scanner.setApplicationContext(applicationContext);
        applicationContext.addBeanFactoryPostProcessor(scanner);
        applicationContext.getBeanFactory().addBeanPostProcessor(scanner);
        applicationContext.getBeanFactory().registerSingleton("annotationBean", scanner);
    }
}
Also used : AnnotationBean(com.alibaba.dubbo.config.spring.AnnotationBean) Environment(org.springframework.core.env.Environment)

Example 25 with Environment

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

the class GenericFilterBean method init.

/**
 * Standard way of initializing this filter.
 * Map config parameters onto bean properties of this filter, and
 * invoke subclass initialization.
 * @param filterConfig the configuration for this filter
 * @throws ServletException if bean properties are invalid (or required
 * properties are missing), or if subclass initialization fails.
 * @see #initFilterBean
 */
@Override
public final void init(FilterConfig filterConfig) throws ServletException {
    Assert.notNull(filterConfig, "FilterConfig must not be null");
    this.filterConfig = filterConfig;
    // Set bean properties from init parameters.
    PropertyValues pvs = new FilterConfigPropertyValues(filterConfig, this.requiredProperties);
    if (!pvs.isEmpty()) {
        try {
            BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this);
            ResourceLoader resourceLoader = new ServletContextResourceLoader(filterConfig.getServletContext());
            Environment env = this.environment;
            if (env == null) {
                env = new StandardServletEnvironment();
            }
            bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader, env));
            initBeanWrapper(bw);
            bw.setPropertyValues(pvs, true);
        } catch (BeansException ex) {
            String msg = "Failed to set bean properties on filter '" + filterConfig.getFilterName() + "': " + ex.getMessage();
            logger.error(msg, ex);
            throw new NestedServletException(msg, ex);
        }
    }
    // Let subclasses do whatever initialization they like.
    initFilterBean();
    if (logger.isDebugEnabled()) {
        logger.debug("Filter '" + filterConfig.getFilterName() + "' configured for use");
    }
}
Also used : ResourceLoader(org.springframework.core.io.ResourceLoader) ServletContextResourceLoader(org.springframework.web.context.support.ServletContextResourceLoader) BeanWrapper(org.springframework.beans.BeanWrapper) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) PropertyValues(org.springframework.beans.PropertyValues) NestedServletException(org.springframework.web.util.NestedServletException) StandardServletEnvironment(org.springframework.web.context.support.StandardServletEnvironment) Environment(org.springframework.core.env.Environment) ResourceEditor(org.springframework.core.io.ResourceEditor) StandardServletEnvironment(org.springframework.web.context.support.StandardServletEnvironment) ServletContextResourceLoader(org.springframework.web.context.support.ServletContextResourceLoader) BeansException(org.springframework.beans.BeansException)

Aggregations

Environment (org.springframework.core.env.Environment)163 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)14 ResourceLoader (org.springframework.core.io.ResourceLoader)13 Collectors (java.util.stream.Collectors)12 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)11 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)9 MutablePropertySources (org.springframework.core.env.MutablePropertySources)9 Map (java.util.Map)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 Predicate (java.util.function.Predicate)7