use of org.springframework.web.context.support.StandardServletEnvironment in project spring-framework by spring-projects.
the class DispatcherServletTests method environmentOperations.
@Test
public void environmentOperations() {
DispatcherServlet servlet = new DispatcherServlet();
ConfigurableEnvironment defaultEnv = servlet.getEnvironment();
assertThat(defaultEnv, notNullValue());
ConfigurableEnvironment env1 = new StandardServletEnvironment();
// should succeed
servlet.setEnvironment(env1);
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));
}
use of org.springframework.web.context.support.StandardServletEnvironment in project hevelian-activemq by Hevelian.
the class WebBrokerInitializerImpl method createBroker.
@Override
protected // TODO throw corresponding exceptions, not just Exception instances.
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);
}
Aggregations