當前位置: 首頁>>代碼示例>>Java>>正文


Java ConfigurableEnvironment.getProperty方法代碼示例

本文整理匯總了Java中org.springframework.core.env.ConfigurableEnvironment.getProperty方法的典型用法代碼示例。如果您正苦於以下問題:Java ConfigurableEnvironment.getProperty方法的具體用法?Java ConfigurableEnvironment.getProperty怎麽用?Java ConfigurableEnvironment.getProperty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.core.env.ConfigurableEnvironment的用法示例。


在下文中一共展示了ConfigurableEnvironment.getProperty方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onApplicationEvent

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
    ConfigurableEnvironment environment = event.getEnvironment();
    configurableEnvironment=environment;
    Properties props = new Properties();

    String databaseMode = environment.getProperty("me.ramon.database-mode");

    if (databaseMode != null) {
        if (databaseMode.equals("hibernate-multitenant")) {
            props.put("spring.jpa.properties.hibernate.multiTenancy", "DATABASE");
            props.put("spring.jpa.properties.hibernate.tenant_identifier_resolver", "me.ramon.multitenancy.BaseCurrentTenantIdentifierResolverImp");
            props.put("spring.jpa.properties.hibernate.multi_tenant_connection_provider", "me.ramon.multitenancy.BaseMultiTenantConnectionProviderImp");
        }
        props.put("spring.jpa.hibernate.ddl-auto", "none");
        props.put("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
        props.put("hibernate.show_sql", "true");
        props.put("logging.level.org.hibernate.SQL", "DEBUG");
        props.put("logging.level.org.hibernate.type.descriptor.sql.BasicBinder", "TRACE");
        props.put("spring.jpa.properties.hibernate.current_session_context_class", "org.springframework.orm.hibernate4.SpringSessionContext");
        environment.getPropertySources().addLast(new PropertiesPropertySource("application1", props));
    }
}
 
開發者ID:mojtaba-sharif,項目名稱:multi-tenancy,代碼行數:23,代碼來源:DefultProperties.java

示例2: main

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
public static void main(String[] args) {
    final SpringApplication app = new SpringApplication(Application.class);
    // save the pid into a file...
    app.addListeners(new ApplicationPidFileWriter("smarti.pid"));

    final ConfigurableApplicationContext context = app.run(args);
    final ConfigurableEnvironment env = context.getEnvironment();

    try {
        //http://localhost:8080/admin/index.html
        final URI uri = new URI(
                (env.getProperty("server.ssl.enabled", Boolean.class, false) ? "https" : "http"),
                null,
                (env.getProperty("server.address", "localhost")),
                (env.getProperty("server.port", Integer.class, 8080)),
                (env.getProperty("server.context-path", "/")).replaceAll("//+", "/"),
                null, null);

        log.info("{} started: {}",
                env.getProperty("server.display-name", context.getDisplayName()),
                uri);
    } catch (URISyntaxException e) {
        log.warn("Could not build launch-url: {}", e.getMessage());
    }
}
 
開發者ID:redlink-gmbh,項目名稱:smarti,代碼行數:26,代碼來源:Application.java

示例3: initializeSystem

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
private void initializeSystem(ConfigurableEnvironment environment,
		LoggingSystem system, LogFile logFile) {
	LoggingInitializationContext initializationContext = new LoggingInitializationContext(
			environment);
	String logConfig = environment.getProperty(CONFIG_PROPERTY);
	if (ignoreLogConfig(logConfig)) {
		system.initialize(initializationContext, null, logFile);
	}
	else {
		try {
			ResourceUtils.getURL(logConfig).openStream().close();
			system.initialize(initializationContext, logConfig, logFile);
		}
		catch (Exception ex) {
			// NOTE: We can't use the logger here to report the problem
			System.err.println("Logging system failed to initialize "
					+ "using configuration from '" + logConfig + "'");
			ex.printStackTrace(System.err);
			throw new IllegalStateException(ex);
		}
	}
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:23,代碼來源:LoggingApplicationListener.java

示例4: getListeners

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private List<ApplicationListener<ApplicationEvent>> getListeners(
		ConfigurableEnvironment env) {
	String classNames = env.getProperty(PROPERTY_NAME);
	List<ApplicationListener<ApplicationEvent>> listeners = new ArrayList<ApplicationListener<ApplicationEvent>>();
	if (StringUtils.hasLength(classNames)) {
		for (String className : StringUtils.commaDelimitedListToSet(classNames)) {
			try {
				Class<?> clazz = ClassUtils.forName(className,
						ClassUtils.getDefaultClassLoader());
				Assert.isAssignable(ApplicationListener.class, clazz, "class ["
						+ className + "] must implement ApplicationListener");
				listeners.add((ApplicationListener<ApplicationEvent>) BeanUtils
						.instantiateClass(clazz));
			}
			catch (Exception ex) {
				throw new ApplicationContextException(
						"Failed to load context listener class [" + className + "]",
						ex);
			}
		}
	}
	AnnotationAwareOrderComparator.sort(listeners);
	return listeners;
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:26,代碼來源:DelegatingApplicationListener.java

示例5: setup

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
@Before
public void setup() throws Exception {
	this.client = new ReactorNettyWebSocketClient();

	this.server = new ReactorHttpServer();
	this.server.setHandler(createHttpHandler());
	this.server.afterPropertiesSet();
	this.server.start();

	// Set dynamically chosen port
	this.serverPort = this.server.getPort();

	if (this.client instanceof Lifecycle) {
		((Lifecycle) this.client).start();
	}

	this.gatewayContext = new SpringApplicationBuilder(GatewayConfig.class)
			.properties("ws.server.port:"+this.serverPort, "server.port=0", "spring.jmx.enabled=false")
			.run();

	GatewayConfig config = this.gatewayContext.getBean(GatewayConfig.class);
	ConfigurableEnvironment env = this.gatewayContext.getBean(ConfigurableEnvironment.class);
	this.gatewayPort = new Integer(env.getProperty("local.server.port"));
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-gateway,代碼行數:25,代碼來源:WebSocketIntegrationTests.java

示例6: postProcessEnvironment

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
    Assert.notNull(propName);
    String val = environment.getProperty(propName);
    if (StringUtils.hasText(val)) {
        List<String> list = Arrays.asList(StringUtils.commaDelimitedListToStringArray(
                environment.resolvePlaceholders(val)));
        Collections.reverse(list);
        for (String item : list) {
            if (!environment.acceptsProfiles(item)) {
                environment.addActiveProfile(item);
                log.info("Added active profile : {}", item);
            } else {
                log.info("Active profile '{}' has already existed.", item);
            }
        }
    }
}
 
開發者ID:easycodebox,項目名稱:easycode,代碼行數:19,代碼來源:ActiveProfileEnvironmentPostProcessor.java

示例7: translateClientVersionProperty

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
private void translateClientVersionProperty(ConfigurableEnvironment environment) {
  if(!environment.containsProperty(CUSTOM_VERSION_PROP)) {
    return;
  }
  String versions = environment.getProperty(CUSTOM_VERSION_PROP);
  Map<String, Object> properties = new HashMap<>();
  properties.put(DEFAULT_VERSION_PROP, versions);
  MapPropertySource target = new MapPropertySource(CLIENT_PROPERTY_SOURCE_NAME, properties);
  environment.getPropertySources().addFirst(target);
}
 
開發者ID:gorelikov,項目名稱:spring-cloud-discovery-version-filter,代碼行數:11,代碼來源:PropertyTranslatorPostProcessor.java

示例8: getProperty

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
private String getProperty(ConfigurableEnvironment env, String propertyName) {
    Assert.notNull(env, "env must not be null!");
    Assert.notNull(propertyName, "propertyName must not be null!");

    final String property = env.getProperty(propertyName);

    if (property == null || property.isEmpty()) {
        throw new IllegalArgumentException("property " + propertyName + " must not be null");
    }
    return property;
}
 
開發者ID:Microsoft,項目名稱:azure-spring-boot,代碼行數:12,代碼來源:KeyVaultEnvironmentPostProcessorHelper.java

示例9: isKeyVaultEnabled

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
private boolean isKeyVaultEnabled(ConfigurableEnvironment environment){
    if (environment.getProperty(Constants.AZURE_CLIENTID) == null) {
        // User doesn't want to enable Key Vault property initializer.
        return false;
    }
    return environment.getProperty(Constants.AZURE_KEYVAULT_ENABLED, Boolean.class, true)
            && isKeyVaultClientAvailable();
}
 
開發者ID:Microsoft,項目名稱:azure-spring-boot,代碼行數:9,代碼來源:KeyVaultEnvironmentPostProcessor.java

示例10: onApplicationEvent

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
@Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
  ConfigurableEnvironment environment = event.getEnvironment();
  String propertySource = environment.getProperty("c2mon.client.conf.url");

  if (propertySource != null) {
    try {
      environment.getPropertySources().addAfter("systemEnvironment", new ResourcePropertySource(propertySource));
    } catch (IOException e) {
      throw new RuntimeException("Could not read property source", e);
    }
  }
}
 
開發者ID:c2mon,項目名稱:c2mon,代碼行數:14,代碼來源:C2monApplicationListener.java

示例11: onApplicationEvent

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
/**
 * Listens for the {@link ApplicationEnvironmentPreparedEvent} and injects
 * ${c2mon.server.properties} into the environment with the highest precedence
 * (if it exists). This is in order to allow users to point to an external
 * properties file via ${c2mon.server.properties}.
 */
@Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
  ConfigurableEnvironment environment = event.getEnvironment();
  String propertySource = environment.getProperty("c2mon.server.properties");

  if (propertySource != null) {
    try {
      environment.getPropertySources().addAfter("systemEnvironment", new ResourcePropertySource(propertySource));
    } catch (IOException e) {
      throw new RuntimeException("Could not read property source", e);
    }
  }
}
 
開發者ID:c2mon,項目名稱:c2mon,代碼行數:20,代碼來源:CommonModule.java

示例12: getInitializerClasses

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
private List<Class<?>> getInitializerClasses(ConfigurableEnvironment env) {
	String classNames = env.getProperty(PROPERTY_NAME);
	List<Class<?>> classes = new ArrayList<Class<?>>();
	if (StringUtils.hasLength(classNames)) {
		for (String className : StringUtils.tokenizeToStringArray(classNames, ",")) {
			classes.add(getInitializerClass(className));
		}
	}
	return classes;
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:11,代碼來源:DelegatingApplicationContextInitializer.java

示例13: findStartIndex

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
private int findStartIndex(ConfigurableEnvironment environment, String binder) {
	String prefix = "spring.cloud.stream." + binder + ".binder.headers";
	int i = 0;
	while (environment.getProperty(prefix + "[" + i + "]")!=null) {
		i++;
	}
	return i;
}
 
開發者ID:reshmik,項目名稱:Zipkin,代碼行數:9,代碼來源:StreamEnvironmentPostProcessor.java

示例14: isSet

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
private boolean isSet(ConfigurableEnvironment environment, String property) {
	String value = environment.getProperty(property);
	return (value != null && !value.equals("false"));
}
 
開發者ID:philwebb,項目名稱:spring-boot-concourse,代碼行數:5,代碼來源:LoggingApplicationListener.java

示例15: getPackageNames

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
@Override
public Set<String> getPackageNames(ConfigurableEnvironment env) {
  @SuppressWarnings("unchecked")
  Set<String> packageNames = env.getProperty("extension-packages", Set.class);
  return packageNames == null ? Collections.<String> emptySet() : packageNames;
}
 
開發者ID:HotelsDotCom,項目名稱:circus-train,代碼行數:7,代碼來源:PropertyExtensionPackageProvider.java


注:本文中的org.springframework.core.env.ConfigurableEnvironment.getProperty方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。