当前位置: 首页>>代码示例>>Java>>正文


Java StandardServletEnvironment类代码示例

本文整理汇总了Java中org.springframework.web.context.support.StandardServletEnvironment的典型用法代码示例。如果您正苦于以下问题:Java StandardServletEnvironment类的具体用法?Java StandardServletEnvironment怎么用?Java StandardServletEnvironment使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


StandardServletEnvironment类属于org.springframework.web.context.support包,在下文中一共展示了StandardServletEnvironment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isWebApplication

import org.springframework.web.context.support.StandardServletEnvironment; //导入依赖的package包/类
private ConditionOutcome isWebApplication(ConditionContext context,
		AnnotatedTypeMetadata metadata, boolean required) {
	ConditionMessage.Builder message = ConditionMessage.forCondition(
			ConditionalOnWebApplication.class, required ? "(required)" : "");
	if (!ClassUtils.isPresent(WEB_CONTEXT_CLASS, context.getClassLoader())) {
		return ConditionOutcome
				.noMatch(message.didNotFind("web application classes").atAll());
	}
	if (context.getBeanFactory() != null) {
		String[] scopes = context.getBeanFactory().getRegisteredScopeNames();
		if (ObjectUtils.containsElement(scopes, "session")) {
			return ConditionOutcome.match(message.foundExactly("'session' scope"));
		}
	}
	if (context.getEnvironment() instanceof StandardServletEnvironment) {
		return ConditionOutcome
				.match(message.foundExactly("StandardServletEnvironment"));
	}
	if (context.getResourceLoader() instanceof WebApplicationContext) {
		return ConditionOutcome.match(message.foundExactly("WebApplicationContext"));
	}
	return ConditionOutcome.noMatch(message.because("not a web application"));
}
 
开发者ID:lodsve,项目名称:lodsve-framework,代码行数:24,代码来源:OnWebApplicationCondition.java

示例2: environmentOperations

import org.springframework.web.context.support.StandardServletEnvironment; //导入依赖的package包/类
@Test
public void environmentOperations() {
	DispatcherServlet servlet = new DispatcherServlet();
	ConfigurableEnvironment defaultEnv = servlet.getEnvironment();
	assertThat(defaultEnv, notNullValue());
	ConfigurableEnvironment env1 = new StandardServletEnvironment();
	servlet.setEnvironment(env1); // should succeed
	assertThat(servlet.getEnvironment(), sameInstance(env1));
	try {
		servlet.setEnvironment(new DummyEnvironment());
		fail("expected IllegalArgumentException for non-configurable Environment");
	}
	catch (IllegalArgumentException ex) {
	}
	class CustomServletEnvironment extends StandardServletEnvironment { }
	@SuppressWarnings("serial")
	DispatcherServlet custom = new DispatcherServlet() {
		@Override
		protected ConfigurableWebEnvironment createEnvironment() {
			return new CustomServletEnvironment();
		}
	};
	assertThat(custom.getEnvironment(), instanceOf(CustomServletEnvironment.class));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:DispatcherServletTests.java

示例3: webEnvironmentSwitchedOffInListener

import org.springframework.web.context.support.StandardServletEnvironment; //导入依赖的package包/类
@Test
public void webEnvironmentSwitchedOffInListener() throws Exception {
	TestSpringApplication application = new TestSpringApplication(
			ExampleConfig.class);
	application.addListeners(
			new ApplicationListener<ApplicationEnvironmentPreparedEvent>() {

				@Override
				public void onApplicationEvent(
						ApplicationEnvironmentPreparedEvent event) {
					assertThat(event.getEnvironment())
							.isInstanceOf(StandardServletEnvironment.class);
					TestPropertySourceUtils.addInlinedPropertiesToEnvironment(
							event.getEnvironment(), "foo=bar");
					event.getSpringApplication().setWebEnvironment(false);
				}

			});
	this.context = application.run();
	assertThat(this.context.getEnvironment())
			.isNotInstanceOf(StandardServletEnvironment.class);
	assertThat(this.context.getEnvironment().getProperty("foo"));
	assertThat(this.context.getEnvironment().getPropertySources().iterator().next()
			.getName()).isEqualTo(
					TestPropertySourceUtils.INLINED_PROPERTIES_PROPERTY_SOURCE_NAME);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:27,代码来源:SpringApplicationTests.java

示例4: isWebApplication

import org.springframework.web.context.support.StandardServletEnvironment; //导入依赖的package包/类
private ConditionOutcome isWebApplication(ConditionContext context,
		AnnotatedTypeMetadata metadata) {

	if (!ClassUtils.isPresent(WEB_CONTEXT_CLASS, context.getClassLoader())) {
		return ConditionOutcome.noMatch("web application classes not found");
	}

	if (context.getBeanFactory() != null) {
		String[] scopes = context.getBeanFactory().getRegisteredScopeNames();
		if (ObjectUtils.containsElement(scopes, "session")) {
			return ConditionOutcome.match("found web application 'session' scope");
		}
	}

	if (context.getEnvironment() instanceof StandardServletEnvironment) {
		return ConditionOutcome
				.match("found web application StandardServletEnvironment");
	}

	if (context.getResourceLoader() instanceof WebApplicationContext) {
		return ConditionOutcome.match("found web application WebApplicationContext");
	}

	return ConditionOutcome.noMatch("not a web application");
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:26,代码来源:OnWebApplicationCondition.java

示例5: postProcessBeanFactory

import org.springframework.web.context.support.StandardServletEnvironment; //导入依赖的package包/类
@Override
public void postProcessBeanFactory(final ConfigurableListableBeanFactory beanFactory) throws BeansException {
    super.postProcessBeanFactory(beanFactory);

    final StandardServletEnvironment propertySources =
            (StandardServletEnvironment) super.getAppliedPropertySources().get(ENVIRONMENT_PROPERTIES).getSource();

    propertySources.getPropertySources().forEach(propertySource -> {
        if (propertySource.getSource() instanceof Map) {
            // it will print systemProperties, systemEnvironment, application.properties and other overrides of
            // application.properties
            log.trace("#######" + propertySource.getName() + "#######");


            //noinspection unchecked
            ((Map) propertySource.getSource()).forEach((key, value) -> log.trace(key+"="+value));
        }
    });
}
 
开发者ID:patexoid,项目名称:ZombieLib2,代码行数:20,代码来源:PropertiesLoaderConfigurer.java

示例6: webEnvironmentSwitchedOffInListener

import org.springframework.web.context.support.StandardServletEnvironment; //导入依赖的package包/类
@Test
public void webEnvironmentSwitchedOffInListener() throws Exception {
	TestSpringApplication application = new TestSpringApplication(
			ExampleConfig.class);
	application.addListeners(
			new ApplicationListener<ApplicationEnvironmentPreparedEvent>() {

				@Override
				public void onApplicationEvent(
						ApplicationEnvironmentPreparedEvent event) {
					assertTrue(event
							.getEnvironment() instanceof StandardServletEnvironment);
					EnvironmentTestUtils.addEnvironment(event.getEnvironment(),
							"foo=bar");
					event.getSpringApplication().setWebEnvironment(false);
				}

			});
	this.context = application.run();
	assertFalse(this.context.getEnvironment() instanceof StandardServletEnvironment);
	assertEquals("bar", this.context.getEnvironment().getProperty("foo"));
	assertEquals("test", this.context.getEnvironment().getPropertySources().iterator()
			.next().getName());
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:25,代码来源:SpringApplicationTests.java

示例7: process_properties_should_decode_all_encrypted_props

import org.springframework.web.context.support.StandardServletEnvironment; //导入依赖的package包/类
/**
 * this test is an integration test (use of a spring context)
 * 
 * It begins with a Jndi instanciation and then try to load a spring context depending on jndi properties.
 * 
 * The goal of this test is to validate that we can read jndi encoded properties from spring
 */
@Test
public void process_properties_should_decode_all_encrypted_props() throws Exception {
	//Jndi setup
	//Set fictive jndi properties (some of them are encoded)
       SimpleNamingContextBuilder.emptyActivatedContextBuilder();
       InitialContext initialContext = new InitialContext();
       initialContext.bind("jndi.prop1", "ENC(VLCeFXg9nPrx7Bmsbcb0h3v5ivRinKQ4)");
       initialContext.bind("jndi.prop2", "testjndiValue2");

       //when
	ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:/com/francetelecom/clara/cloud/commons/jasypt/jndiPropsDecoding.xml"){
		@Override
		protected ConfigurableEnvironment createEnvironment() {
			return new StandardServletEnvironment();
		}
	};
	
	//Then
	TestBean bean = context.getBean(TestBean.class);
	assertEquals("testjndivalue",bean.getSampleProp1());
	assertEquals("testjndiValue2",bean.getSampleProp2());
	assertEquals("testlocalvalue",bean.getSampleProp3());
	assertEquals("testlocalvalue2",bean.getSampleProp4());
}
 
开发者ID:orange-cloudfoundry,项目名称:elpaaso-core,代码行数:32,代码来源:EncryptablePropertySourcesPlaceholderConfigurerTest.java

示例8: testEnvironmentOperations

import org.springframework.web.context.support.StandardServletEnvironment; //导入依赖的package包/类
public void testEnvironmentOperations() {
	DispatcherServlet servlet = new DispatcherServlet();
	ConfigurableEnvironment defaultEnv = servlet.getEnvironment();
	assertThat(defaultEnv, notNullValue());
	ConfigurableEnvironment env1 = new StandardServletEnvironment();
	servlet.setEnvironment(env1); // should succeed
	assertThat(servlet.getEnvironment(), sameInstance(env1));
	try {
		servlet.setEnvironment(new DummyEnvironment());
		fail("expected IllegalArgumentException for non-configurable Environment");
	}
	catch (IllegalArgumentException ex) {
	}
	class CustomServletEnvironment extends StandardServletEnvironment { }
	@SuppressWarnings("serial")
	DispatcherServlet custom = new DispatcherServlet() {
		@Override
		protected ConfigurableWebEnvironment createEnvironment() {
			return new CustomServletEnvironment();
		}
	};
	assertThat(custom.getEnvironment(), instanceOf(CustomServletEnvironment.class));
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:24,代码来源:DispatcherServletTests.java

示例9: createBroker

import org.springframework.web.context.support.StandardServletEnvironment; //导入依赖的package包/类
@Override
// TODO throw corresponding exceptions, not just Exception instances.
protected BrokerService createBroker(ServletContext sc) throws Exception {
	// Initialize Web environment to make Spring resolve external
	// properties.
	StandardServletEnvironment standardServletEnvironment = new ReversePropertySourcesStandardServletEnvironment();
	WebApplicationContextUtils.initServletPropertySources(standardServletEnvironment.getPropertySources(), sc);

	URI configURI = new URI(standardServletEnvironment.getProperty(BROKER_URI_PROP));

	LOG.info("Loading message broker from: " + configURI);
	return BrokerFactory.createBroker(configURI);
}
 
开发者ID:Hevelian,项目名称:hevelian-activemq,代码行数:14,代码来源:WebBrokerInitializerImpl.java

示例10: customizePropertySources

import org.springframework.web.context.support.StandardServletEnvironment; //导入依赖的package包/类
@Test
public void customizePropertySources() {
	MutablePropertySources propertySources = new MutablePropertySources();
	ReversePropertySourcesStandardServletEnvironment env = new ReversePropertySourcesStandardServletEnvironment();
	env.customizePropertySources(propertySources);
	
	String[] sourceNames = { StandardServletEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME,
			StandardServletEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME,
			StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME,
			StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME };
	List<String> result = new ArrayList<>();
	propertySources.forEach(a -> result.add(a.getName()));
	Assert.assertArrayEquals(sourceNames, result.toArray());
}
 
开发者ID:Hevelian,项目名称:hevelian-activemq,代码行数:15,代码来源:ReversePropertySourcesStandardServletEnvironmentTest.java

示例11: registerServletParamPropertySources_GenericWebApplicationContext

import org.springframework.web.context.support.StandardServletEnvironment; //导入依赖的package包/类
@Test
public void registerServletParamPropertySources_GenericWebApplicationContext() {
	MockServletContext servletContext = new MockServletContext();
	servletContext.addInitParameter("pCommon", "pCommonContextValue");
	servletContext.addInitParameter("pContext1", "pContext1Value");

	GenericWebApplicationContext ctx = new GenericWebApplicationContext();
	ctx.setServletContext(servletContext);
	ctx.refresh();

	ConfigurableEnvironment environment = ctx.getEnvironment();
	assertThat(environment, instanceOf(StandardServletEnvironment.class));
	MutablePropertySources propertySources = environment.getPropertySources();
	assertThat(propertySources.contains(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME), is(true));

	// ServletContext params are available
	assertThat(environment.getProperty("pCommon"), is("pCommonContextValue"));
	assertThat(environment.getProperty("pContext1"), is("pContext1Value"));

	// Servlet* PropertySources have precedence over System* PropertySources
	assertThat(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)),
			lessThan(propertySources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME))));

	// Replace system properties with a mock property source for convenience
	MockPropertySource mockSystemProperties = new MockPropertySource(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME);
	mockSystemProperties.setProperty("pCommon", "pCommonSysPropsValue");
	mockSystemProperties.setProperty("pSysProps1", "pSysProps1Value");
	propertySources.replace(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME, mockSystemProperties);

	// assert that servletcontext init params resolve with higher precedence than sysprops
	assertThat(environment.getProperty("pCommon"), is("pCommonContextValue"));
	assertThat(environment.getProperty("pSysProps1"), is("pSysProps1Value"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:34,代码来源:EnvironmentSystemIntegrationTests.java

示例12: findPropertySource

import org.springframework.web.context.support.StandardServletEnvironment; //导入依赖的package包/类
private String findPropertySource(MutablePropertySources sources) {
	if (ClassUtils.isPresent(SERVLET_ENVIRONMENT_CLASS, null) && sources
			.contains(StandardServletEnvironment.JNDI_PROPERTY_SOURCE_NAME)) {
		return StandardServletEnvironment.JNDI_PROPERTY_SOURCE_NAME;

	}
	return StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME;
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:9,代码来源:SpringApplicationJsonEnvironmentPostProcessor.java

示例13: getOrCreateEnvironment

import org.springframework.web.context.support.StandardServletEnvironment; //导入依赖的package包/类
private ConfigurableEnvironment getOrCreateEnvironment() {
	if (this.environment != null) {
		return this.environment;
	}
	if (this.webEnvironment) {
		return new StandardServletEnvironment();
	}
	return new StandardEnvironment();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:10,代码来源:SpringApplication.java

示例14: getOrCreateEnvironment

import org.springframework.web.context.support.StandardServletEnvironment; //导入依赖的package包/类
private ConfigurableEnvironment getOrCreateEnvironment() {
	if (this.environment != null) {
		return this.environment;
	}
	if (this.webEnvironment) {
		return new StandardServletEnvironment();
	}
	return new StandardEnvironment();

}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:11,代码来源:SpringApplication.java

示例15: setUp

import org.springframework.web.context.support.StandardServletEnvironment; //导入依赖的package包/类
@Before
public void setUp() {
	prodEnv = new StandardEnvironment();
	prodEnv.setActiveProfiles(PROD_ENV_NAME);

	devEnv = new StandardEnvironment();
	devEnv.setActiveProfiles(DEV_ENV_NAME);

	prodWebEnv = new StandardServletEnvironment();
	prodWebEnv.setActiveProfiles(PROD_ENV_NAME);
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:12,代码来源:EnvironmentIntegrationTests.java


注:本文中的org.springframework.web.context.support.StandardServletEnvironment类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。