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


Java StandardEnvironment類代碼示例

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


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

示例1: addKeyVaultPropertySource

import org.springframework.core.env.StandardEnvironment; //導入依賴的package包/類
public void addKeyVaultPropertySource() {
    final String clientId = getProperty(environment, Constants.AZURE_CLIENTID);
    final String clientKey = getProperty(environment, Constants.AZURE_CLIENTKEY);
    final String vaultUri = getProperty(environment, Constants.AZURE_KEYVAULT_VAULT_URI);

    final long timeAcquiringTimeoutInSeconds = environment.getProperty(
            Constants.AZURE_TOKEN_ACQUIRE_TIMEOUT_IN_SECONDS, Long.class, 60L);

    final KeyVaultClient kvClient = new KeyVaultClient(
            new AzureKeyVaultCredential(clientId, clientKey, timeAcquiringTimeoutInSeconds));

    try {
        final MutablePropertySources sources = environment.getPropertySources();
        final KeyVaultOperation kvOperation = new KeyVaultOperation(kvClient, vaultUri);

        if (sources.contains(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME)) {
            sources.addAfter(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME,
                    new KeyVaultPropertySource(kvOperation));
        } else {
            sources.addFirst(new KeyVaultPropertySource(kvOperation));
        }

    } catch (Exception ex) {
        throw new IllegalStateException("Failed to configure KeyVault property source", ex);
    }
}
 
開發者ID:Microsoft,項目名稱:azure-spring-boot,代碼行數:27,代碼來源:KeyVaultEnvironmentPostProcessorHelper.java

示例2: AbstractBeanDefinitionReader

import org.springframework.core.env.StandardEnvironment; //導入依賴的package包/類
/**
 * Create a new AbstractBeanDefinitionReader for the given bean factory.
 * <p>If the passed-in bean factory does not only implement the BeanDefinitionRegistry
 * interface but also the ResourceLoader interface, it will be used as default
 * ResourceLoader as well. This will usually be the case for
 * {@link org.springframework.context.ApplicationContext} implementations.
 * <p>If given a plain BeanDefinitionRegistry, the default ResourceLoader will be a
 * {@link org.springframework.core.io.support.PathMatchingResourcePatternResolver}.
 * <p>If the the passed-in bean factory also implements {@link EnvironmentCapable} its
 * environment will be used by this reader.  Otherwise, the reader will initialize and
 * use a {@link StandardEnvironment}. All ApplicationContext implementations are
 * EnvironmentCapable, while normal BeanFactory implementations are not.
 * @param registry the BeanFactory to load bean definitions into,
 * in the form of a BeanDefinitionRegistry
 * @see #setResourceLoader
 * @see #setEnvironment
 */
protected AbstractBeanDefinitionReader(BeanDefinitionRegistry registry) {
	Assert.notNull(registry, "BeanDefinitionRegistry must not be null");
	this.registry = registry;

	// Determine ResourceLoader to use.
	if (this.registry instanceof ResourceLoader) {
		this.resourceLoader = (ResourceLoader) this.registry;
	}
	else {
		this.resourceLoader = new PathMatchingResourcePatternResolver();
	}

	// Inherit Environment if possible
	if (this.registry instanceof EnvironmentCapable) {
		this.environment = ((EnvironmentCapable) this.registry).getEnvironment();
	}
	else {
		this.environment = new StandardEnvironment();
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:38,代碼來源:AbstractBeanDefinitionReader.java

示例3: createSqlSessionFactoryBean

import org.springframework.core.env.StandardEnvironment; //導入依賴的package包/類
protected final AbstractBeanDefinition createSqlSessionFactoryBean(String dataSourceName, String mapperPackage,
		String typeAliasesPackage, Dialect dialect, Configuration configuration) {
	configuration.setDatabaseId(dataSourceName);
	BeanDefinitionBuilder bdb = BeanDefinitionBuilder.rootBeanDefinition(SqlSessionFactoryBean.class);
	bdb.addPropertyValue("configuration", configuration);
	bdb.addPropertyValue("failFast", true);
	bdb.addPropertyValue("typeAliases", this.saenTypeAliases(typeAliasesPackage));
	bdb.addPropertyReference("dataSource", dataSourceName);
	bdb.addPropertyValue("plugins", new Interceptor[] { new CustomPageInterceptor(dialect) });
	if (!StringUtils.isEmpty(mapperPackage)) {
		try {
			mapperPackage = new StandardEnvironment().resolveRequiredPlaceholders(mapperPackage);
			String mapperPackages = ClassUtils.convertClassNameToResourcePath(mapperPackage);
			String mapperPackagePath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + mapperPackages + "/*.xml";
			Resource[] resources = new PathMatchingResourcePatternResolver().getResources(mapperPackagePath);
			bdb.addPropertyValue("mapperLocations", resources);
		} catch (Exception e) {
			log.error("初始化失敗", e);
			throw new RuntimeException( String.format("SqlSessionFactory 初始化失敗  mapperPackage=%s", mapperPackage + ""));
		}
	}
	return bdb.getBeanDefinition();
}
 
開發者ID:halober,項目名稱:spring-boot-starter-dao,代碼行數:24,代碼來源:AbstractDataBaseBean.java

示例4: customPlaceholderPrefixAndSuffix

import org.springframework.core.env.StandardEnvironment; //導入依賴的package包/類
@Test
public void customPlaceholderPrefixAndSuffix() {
	PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();
	ppc.setPlaceholderPrefix("@<");
	ppc.setPlaceholderSuffix(">");

	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	bf.registerBeanDefinition("testBean",
			rootBeanDefinition(TestBean.class)
			.addPropertyValue("name", "@<key1>")
			.addPropertyValue("sex", "${key2}")
			.getBeanDefinition());

	System.setProperty("key1", "systemKey1Value");
	System.setProperty("key2", "systemKey2Value");
	ppc.setEnvironment(new StandardEnvironment());
	ppc.postProcessBeanFactory(bf);
	System.clearProperty("key1");
	System.clearProperty("key2");

	assertThat(bf.getBean(TestBean.class).getName(), is("systemKey1Value"));
	assertThat(bf.getBean(TestBean.class).getSex(), is("${key2}"));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:24,代碼來源:PropertySourcesPlaceholderConfigurerTests.java

示例5: getBean_withActiveProfile

import org.springframework.core.env.StandardEnvironment; //導入依賴的package包/類
@Test
public void getBean_withActiveProfile() {
	ConfigurableEnvironment env = new StandardEnvironment();
	env.setActiveProfiles("dev");

	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(bf);
	reader.setEnvironment(env);
	reader.loadBeanDefinitions(XML);

	bf.getBean("devOnlyBean"); // should not throw NSBDE

	Object foo = bf.getBean("foo");
	assertThat(foo, instanceOf(Integer.class));

	bf.getBean("devOnlyBean");
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:18,代碼來源:NestedBeansElementTests.java

示例6: loadContext

import org.springframework.core.env.StandardEnvironment; //導入依賴的package包/類
@Override
public ApplicationContext loadContext(MergedContextConfiguration config)
		throws Exception {
	SpringApplication application = new SpringApplication();
	application.setMainApplicationClass(config.getTestClass());
	application.setWebEnvironment(false);
	application.setSources(
			new LinkedHashSet<Object>(Arrays.asList(config.getClasses())));
	ConfigurableEnvironment environment = new StandardEnvironment();
	Map<String, Object> properties = new LinkedHashMap<String, Object>();
	properties.put("spring.jmx.enabled", "false");
	properties.putAll(TestPropertySourceUtils
			.convertInlinedPropertiesToMap(config.getPropertySourceProperties()));
	environment.getPropertySources().addAfter(
			StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME,
			new MapPropertySource("integrationTest", properties));
	application.setEnvironment(environment);
	return application.run();
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:20,代碼來源:SpringApplicationBindContextLoader.java

示例7: loadContext

import org.springframework.core.env.StandardEnvironment; //導入依賴的package包/類
@Override
public ApplicationContext loadContext(final MergedContextConfiguration config)
		throws Exception {
	assertValidAnnotations(config.getTestClass());
	SpringApplication application = getSpringApplication();
	application.setMainApplicationClass(config.getTestClass());
	application.setSources(getSources(config));
	ConfigurableEnvironment environment = new StandardEnvironment();
	if (!ObjectUtils.isEmpty(config.getActiveProfiles())) {
		setActiveProfiles(environment, config.getActiveProfiles());
	}
	Map<String, Object> properties = getEnvironmentProperties(config);
	addProperties(environment, properties);
	application.setEnvironment(environment);
	List<ApplicationContextInitializer<?>> initializers = getInitializers(config,
			application);
	if (config instanceof WebMergedContextConfiguration) {
		new WebConfigurer().configure(config, application, initializers);
	}
	else {
		application.setWebEnvironment(false);
	}
	application.setInitializers(initializers);
	ConfigurableApplicationContext applicationContext = application.run();
	return applicationContext;
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:27,代碼來源:SpringApplicationContextLoader.java

示例8: AbstractBeanDefinitionReader

import org.springframework.core.env.StandardEnvironment; //導入依賴的package包/類
/**
 * Create a new AbstractBeanDefinitionReader for the given bean factory.
 * <p>If the passed-in bean factory does not only implement the BeanDefinitionRegistry
 * interface but also the ResourceLoader interface, it will be used as default
 * ResourceLoader as well. This will usually be the case for
 * {@link org.springframework.context.ApplicationContext} implementations.
 * <p>If given a plain BeanDefinitionRegistry, the default ResourceLoader will be a
 * {@link org.springframework.core.io.support.PathMatchingResourcePatternResolver}.
 * <p>If the passed-in bean factory also implements {@link EnvironmentCapable} its
 * environment will be used by this reader.  Otherwise, the reader will initialize and
 * use a {@link StandardEnvironment}. All ApplicationContext implementations are
 * EnvironmentCapable, while normal BeanFactory implementations are not.
 * @param registry the BeanFactory to load bean definitions into,
 * in the form of a BeanDefinitionRegistry
 * @see #setResourceLoader
 * @see #setEnvironment
 */
protected AbstractBeanDefinitionReader(BeanDefinitionRegistry registry) {
	Assert.notNull(registry, "BeanDefinitionRegistry must not be null");
	this.registry = registry;

	// Determine ResourceLoader to use.
	if (this.registry instanceof ResourceLoader) {
		this.resourceLoader = (ResourceLoader) this.registry;
	}
	else {
		this.resourceLoader = new PathMatchingResourcePatternResolver();
	}

	// Inherit Environment if possible
	if (this.registry instanceof EnvironmentCapable) {
		this.environment = ((EnvironmentCapable) this.registry).getEnvironment();
	}
	else {
		this.environment = new StandardEnvironment();
	}
}
 
開發者ID:txazo,項目名稱:spring,代碼行數:38,代碼來源:AbstractBeanDefinitionReader.java

示例9: setup

import org.springframework.core.env.StandardEnvironment; //導入依賴的package包/類
@Before
public void setup() {
    mockEnvironment = mock(StandardEnvironment.class);

    when(mockEnvironment.getProperty(HmpProperties.JMEADOWS_URL)).thenReturn("test.url");
    when(mockEnvironment.getProperty(HmpProperties.JMEADOWS_TIMEOUT_MS)).thenReturn("45000");
    when(mockEnvironment.getProperty(HmpProperties.JMEADOWS_USER_NAME)).thenReturn("test.username");
    when(mockEnvironment.getProperty(HmpProperties.JMEADOWS_USER_IEN)).thenReturn("test.ien");
    when(mockEnvironment.getProperty(HmpProperties.JMEADOWS_USER_SITE_CODE)).thenReturn("test.sitecode");
    when(mockEnvironment.getProperty(HmpProperties.JMEADOWS_USER_SITE_NAME)).thenReturn("test.sitename");

    JMeadowsConfiguration jMeadowsConfiguration = new JMeadowsConfiguration(mockEnvironment);

    jMeadowsPatientService = new JMeadowsPatientService();
    jMeadowsPatientService.init();
    jMeadowsPatientService.setJMeadowsConfiguration(jMeadowsConfiguration);

}
 
開發者ID:KRMAssociatesInc,項目名稱:eHMP,代碼行數:19,代碼來源:JMeadowsPatientServiceTest.java

示例10: setup

import org.springframework.core.env.StandardEnvironment; //導入依賴的package包/類
@Before
public void setup() {
    mockEnvironment = mock(StandardEnvironment.class);
    when(mockEnvironment.getProperty(HmpProperties.JMEADOWS_URL)).thenReturn(url);
    when(mockEnvironment.getProperty(HmpProperties.JMEADOWS_TIMEOUT_MS)).thenReturn("" + timeoutMS);
    when(mockEnvironment.getProperty(HmpProperties.JMEADOWS_USER_NAME)).thenReturn(userName);
    when(mockEnvironment.getProperty(HmpProperties.JMEADOWS_USER_IEN)).thenReturn(userIen);
    when(mockEnvironment.getProperty(HmpProperties.JMEADOWS_USER_SITE_CODE)).thenReturn(userSiteCode);
    when(mockEnvironment.getProperty(HmpProperties.JMEADOWS_USER_SITE_NAME)).thenReturn(userSiteName);

    this.mockJMeadowsClient = mock(JMeadowsData.class);
    this.mockJMeadowsOrderService = new JMeadowsOrderService(new JMeadowsConfiguration(mockEnvironment));
    this.mockJMeadowsOrderService.setJMeadowsClient(mockJMeadowsClient);

    user = new User();
    user.setUserIen("test.ien");
    Site hostSite = new Site();
    hostSite.setSiteCode("test.site.code");
    hostSite.setAgency("VA");
    hostSite.setMoniker("test.moniker");
    hostSite.setName("test.site.name");
    user.setHostSite(hostSite);

    patient = new Patient();
    patient.setEDIPI("test.edipi");
}
 
開發者ID:KRMAssociatesInc,項目名稱:eHMP,代碼行數:27,代碼來源:JMeadowsOrderServiceTest.java

示例11: setup

import org.springframework.core.env.StandardEnvironment; //導入依賴的package包/類
@Before
public void setup() {
    mockEnvironment = mock(StandardEnvironment.class);
    when(mockEnvironment.getProperty(HmpProperties.JMEADOWS_URL)).thenReturn(url);
    when(mockEnvironment.getProperty(HmpProperties.JMEADOWS_TIMEOUT_MS)).thenReturn("" + timeoutMS);
    when(mockEnvironment.getProperty(HmpProperties.JMEADOWS_USER_NAME)).thenReturn(userName);
    when(mockEnvironment.getProperty(HmpProperties.JMEADOWS_USER_IEN)).thenReturn(userIen);
    when(mockEnvironment.getProperty(HmpProperties.JMEADOWS_USER_SITE_CODE)).thenReturn(userSiteCode);
    when(mockEnvironment.getProperty(HmpProperties.JMEADOWS_USER_SITE_NAME)).thenReturn(userSiteName);

    this.mockJMeadowsClient = mock(JMeadowsData.class);
    this.jMeadowsImmunizationService = new JMeadowsImmunizationService(new JMeadowsConfiguration(mockEnvironment));
    this.jMeadowsImmunizationService.setJMeadowsClient(mockJMeadowsClient);

    user = new User();
    user.setUserIen("test.ien");
    Site hostSite = new Site();
    hostSite.setSiteCode("test.site.code");
    hostSite.setAgency("VA");
    hostSite.setMoniker("test.moniker");
    hostSite.setName("test.site.name");
    user.setHostSite(hostSite);

    patient = new Patient();
    patient.setEDIPI("test.edipi");
}
 
開發者ID:KRMAssociatesInc,項目名稱:eHMP,代碼行數:27,代碼來源:JMeadowsImmunizationServiceTest.java

示例12: setup

import org.springframework.core.env.StandardEnvironment; //導入依賴的package包/類
@Before
public void setup() {
    mockEnvironment = mock(StandardEnvironment.class);
    when(mockEnvironment.getProperty(HmpProperties.JMEADOWS_URL)).thenReturn(url);
    when(mockEnvironment.getProperty(HmpProperties.JMEADOWS_TIMEOUT_MS)).thenReturn("" + timeoutMS);
    when(mockEnvironment.getProperty(HmpProperties.JMEADOWS_USER_NAME)).thenReturn(userName);
    when(mockEnvironment.getProperty(HmpProperties.JMEADOWS_USER_IEN)).thenReturn(userIen);
    when(mockEnvironment.getProperty(HmpProperties.JMEADOWS_USER_SITE_CODE)).thenReturn(userSiteCode);
    when(mockEnvironment.getProperty(HmpProperties.JMEADOWS_USER_SITE_NAME)).thenReturn(userSiteName);

    this.mockJMeadowsClient = mock(JMeadowsData.class);
    this.jMeadowsVitalService = new JMeadowsVitalService(new JMeadowsConfiguration(mockEnvironment));
    this.jMeadowsVitalService.setJMeadowsClient(mockJMeadowsClient);

    user = new User();
    user.setUserIen("test.ien");
    Site hostSite = new Site();
    hostSite.setSiteCode("test.site.code");
    hostSite.setAgency("VA");
    hostSite.setMoniker("test.moniker");
    hostSite.setName("test.site.name");
    user.setHostSite(hostSite);

    patient = new Patient();
    patient.setEDIPI("test.edipi");
}
 
開發者ID:KRMAssociatesInc,項目名稱:eHMP,代碼行數:27,代碼來源:JMeadowsVitalServiceTest.java

示例13: shouldWrapExceptionOnEncryptionError

import org.springframework.core.env.StandardEnvironment; //導入依賴的package包/類
@Test
public void shouldWrapExceptionOnEncryptionError() {
    // given
    StandardEnvironment environment = new StandardEnvironment();
    Properties props = new Properties();
    props.put("propertyDecryption.password", "NOT-A-PASSWORD");
    props.put("someProperty", "{encrypted}NOT-ENCRYPTED");
    environment.getPropertySources().addFirst(new PropertiesPropertySource("test-env", props));

    exception.expect(RuntimeException.class);
    exception.expectMessage("Unable to decrypt property value '{encrypted}NOT-ENCRYPTED'");
    exception.expectCause(isA(EncryptionOperationNotPossibleException.class));

    ApplicationEnvironmentPreparedEvent event = new ApplicationEnvironmentPreparedEvent(new SpringApplication(), new String[0], environment);

    // when
    listener.onApplicationEvent(event);

    // then -> exception
}
 
開發者ID:lukashinsch,項目名稱:spring-properties-decrypter,代碼行數:21,代碼來源:DecryptingPropertiesApplicationListenerTest.java

示例14: copyEnvironment

import org.springframework.core.env.StandardEnvironment; //導入依賴的package包/類
private StandardEnvironment copyEnvironment(ConfigurableEnvironment input) {
	StandardEnvironment environment = new StandardEnvironment();
	MutablePropertySources capturedPropertySources = environment.getPropertySources();
	// Only copy the default property source(s) and the profiles over from the main
	// environment (everything else should be pristine, just like it was on startup).
	for (String name : DEFAULT_PROPERTY_SOURCES) {
		if (input.getPropertySources().contains(name)) {
			if (capturedPropertySources.contains(name)) {
				capturedPropertySources.replace(name,
						input.getPropertySources().get(name));
			}
			else {
				capturedPropertySources.addLast(input.getPropertySources().get(name));
			}
		}
	}
	environment.setActiveProfiles(input.getActiveProfiles());
	environment.setDefaultProfiles(input.getDefaultProfiles());
	Map<String, Object> map = new HashMap<String, Object>();
	map.put("spring.jmx.enabled", false);
	map.put("spring.main.sources", "");
	capturedPropertySources
			.addFirst(new MapPropertySource(REFRESH_ARGS_PROPERTY_SOURCE, map));
	return environment;
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-commons,代碼行數:26,代碼來源:ContextRefresher.java

示例15: createApplicationContext

import org.springframework.core.env.StandardEnvironment; //導入依賴的package包/類
/**
 * Create Spring Bean factory. Parameter 'springContext' can be null.
 *
 * Create the Spring Bean Factory using the supplied <code>springContext</code>,
 * if not <code>null</code>.
 *
 * @param springContext Spring Context to create. If <code>null</code>,
 * use the default spring context.
 * The spring context is loaded as a spring ClassPathResource from
 * the class path.
 *
 * @return The Spring XML Bean Factory.
 * @throws BeansException If the Factory can not be created.
 *
 */
private ApplicationContext createApplicationContext() throws BeansException {
	// Reading in Spring Context
	long start = System.currentTimeMillis();
	String springContext = "/springContext.xml";
	ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext();
	MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources();
	propertySources.remove(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME);
	propertySources.remove(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME);
	propertySources.addFirst(new PropertiesPropertySource("ibis", APP_CONSTANTS));
	applicationContext.setConfigLocation(springContext);
	applicationContext.refresh();
	log("startup " + springContext + " in "
			+ (System.currentTimeMillis() - start) + " ms");
	return applicationContext;
}
 
開發者ID:ibissource,項目名稱:iaf,代碼行數:31,代碼來源:IbisContext.java


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