Search in sources :

Example 76 with ApplicationContext

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));
}
Also used : AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ViewResolverComposite(org.springframework.web.servlet.view.ViewResolverComposite) Test(org.junit.Test)

Example 77 with ApplicationContext

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);
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ApplicationContext(org.springframework.context.ApplicationContext) ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig)

Example 78 with ApplicationContext

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);
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)

Example 79 with ApplicationContext

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);
    }
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) BeansException(org.springframework.beans.BeansException)

Example 80 with ApplicationContext

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());
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) SimpleBrokerMessageHandler(org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler) ThreadPoolTaskScheduler(org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler) Test(org.junit.Test)

Aggregations

ApplicationContext (org.springframework.context.ApplicationContext)578 Test (org.junit.Test)262 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)179 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)44 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)37 ConfigurableMessenger (org.springframework.scripting.ConfigurableMessenger)28 File (java.io.File)25 DataSource (javax.sql.DataSource)24 Messenger (org.springframework.scripting.Messenger)24 GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)21 Refreshable (org.springframework.aop.target.dynamic.Refreshable)20 StubCloudConnectorTest (org.springframework.cloud.StubCloudConnectorTest)17 HashMap (java.util.HashMap)16 SchedulerException (org.quartz.SchedulerException)16 ArrayList (java.util.ArrayList)14 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)14 WebApplicationContext (org.springframework.web.context.WebApplicationContext)14 MovieMapper (com.mapper.MovieMapper)13 Map (java.util.Map)13 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)13