use of org.springframework.context.ApplicationContext in project spring-framework by spring-projects.
the class WebMvcConfigurationSupportTests method mvcViewResolverWithExistingResolver.
@Test
public void mvcViewResolverWithExistingResolver() throws Exception {
ApplicationContext context = initContext(WebConfig.class, ViewResolverConfig.class);
ViewResolverComposite resolver = context.getBean("mvcViewResolver", ViewResolverComposite.class);
assertNotNull(resolver);
assertEquals(0, resolver.getViewResolvers().size());
assertEquals(Ordered.LOWEST_PRECEDENCE, resolver.getOrder());
assertNull(resolver.resolveViewName("anyViewName", Locale.ENGLISH));
}
use of org.springframework.context.ApplicationContext in project spring-framework by spring-projects.
the class ServerEndpointExporter method registerEndpoints.
/**
* Actually register the endpoints. Called by {@link #afterSingletonsInstantiated()}.
*/
protected void registerEndpoints() {
Set<Class<?>> endpointClasses = new LinkedHashSet<>();
if (this.annotatedEndpointClasses != null) {
endpointClasses.addAll(this.annotatedEndpointClasses);
}
ApplicationContext context = getApplicationContext();
if (context != null) {
String[] endpointBeanNames = context.getBeanNamesForAnnotation(ServerEndpoint.class);
for (String beanName : endpointBeanNames) {
endpointClasses.add(context.getType(beanName));
}
}
for (Class<?> endpointClass : endpointClasses) {
registerEndpoint(endpointClass);
}
if (context != null) {
Map<String, ServerEndpointConfig> endpointConfigMap = context.getBeansOfType(ServerEndpointConfig.class);
for (ServerEndpointConfig endpointConfig : endpointConfigMap.values()) {
registerEndpoint(endpointConfig);
}
}
}
use of org.springframework.context.ApplicationContext in project spring-framework by spring-projects.
the class ConvertingEncoderDecoderSupport method init.
/**
* @see javax.websocket.Encoder#init(EndpointConfig)
* @see javax.websocket.Decoder#init(EndpointConfig)
*/
public void init(EndpointConfig config) {
ApplicationContext applicationContext = getApplicationContext();
if (applicationContext != null && applicationContext instanceof ConfigurableApplicationContext) {
ConfigurableListableBeanFactory beanFactory = ((ConfigurableApplicationContext) applicationContext).getBeanFactory();
beanFactory.autowireBean(this);
}
}
use of org.springframework.context.ApplicationContext in project spring-framework by spring-projects.
the class ConvertingEncoderDecoderSupport method getConversionService.
/**
* Strategy method used to obtain the {@link ConversionService}. By default this
* method expects a bean named {@code 'webSocketConversionService'} in the
* {@link #getApplicationContext() active ApplicationContext}.
* @return the {@link ConversionService} (never null)
*/
protected ConversionService getConversionService() {
ApplicationContext applicationContext = getApplicationContext();
Assert.state(applicationContext != null, "Unable to locate the Spring ApplicationContext");
try {
return applicationContext.getBean(CONVERSION_SERVICE_BEAN_NAME, ConversionService.class);
} catch (BeansException ex) {
throw new IllegalStateException("Unable to find ConversionService: please configure a '" + CONVERSION_SERVICE_BEAN_NAME + "' or override the getConversionService() method", ex);
}
}
use of org.springframework.context.ApplicationContext in project spring-framework by spring-projects.
the class WebSocketMessageBrokerConfigurationSupportTests method taskScheduler.
@Test
public void taskScheduler() {
ApplicationContext config = createConfig(TestChannelConfig.class, TestConfigurer.class);
String name = "messageBrokerSockJsTaskScheduler";
ThreadPoolTaskScheduler taskScheduler = config.getBean(name, ThreadPoolTaskScheduler.class);
ScheduledThreadPoolExecutor executor = taskScheduler.getScheduledThreadPoolExecutor();
assertEquals(Runtime.getRuntime().availableProcessors(), executor.getCorePoolSize());
assertTrue(executor.getRemoveOnCancelPolicy());
SimpleBrokerMessageHandler handler = config.getBean(SimpleBrokerMessageHandler.class);
assertNotNull(handler.getTaskScheduler());
assertArrayEquals(new long[] { 15000, 15000 }, handler.getHeartbeatValue());
}
Aggregations