Search in sources :

Example 16 with NoSuchBeanDefinitionException

use of org.springframework.beans.factory.NoSuchBeanDefinitionException in project spring-framework by spring-projects.

the class ConfigurationClassPostProcessorTests method assertSupportForComposedAnnotationWithExclude.

private void assertSupportForComposedAnnotationWithExclude(RootBeanDefinition beanDefinition) {
    beanFactory.registerBeanDefinition("config", beanDefinition);
    ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
    pp.setEnvironment(new StandardEnvironment());
    pp.postProcessBeanFactory(beanFactory);
    try {
        beanFactory.getBean(SimpleComponent.class);
        fail("Should have thrown NoSuchBeanDefinitionException");
    } catch (NoSuchBeanDefinitionException ex) {
    // expected
    }
}
Also used : NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) StandardEnvironment(org.springframework.core.env.StandardEnvironment)

Example 17 with NoSuchBeanDefinitionException

use of org.springframework.beans.factory.NoSuchBeanDefinitionException in project spring-framework by spring-projects.

the class JmsListenerAnnotationBeanPostProcessor method processJmsListener.

/**
	 * Process the given {@link JmsListener} annotation on the given method,
	 * registering a corresponding endpoint for the given bean instance.
	 * @param jmsListener the annotation to process
	 * @param mostSpecificMethod the annotated method
	 * @param bean the instance to invoke the method on
	 * @see #createMethodJmsListenerEndpoint()
	 * @see JmsListenerEndpointRegistrar#registerEndpoint
	 */
protected void processJmsListener(JmsListener jmsListener, Method mostSpecificMethod, Object bean) {
    Method invocableMethod = AopUtils.selectInvocableMethod(mostSpecificMethod, bean.getClass());
    MethodJmsListenerEndpoint endpoint = createMethodJmsListenerEndpoint();
    endpoint.setBean(bean);
    endpoint.setMethod(invocableMethod);
    endpoint.setMostSpecificMethod(mostSpecificMethod);
    endpoint.setMessageHandlerMethodFactory(this.messageHandlerMethodFactory);
    endpoint.setEmbeddedValueResolver(this.embeddedValueResolver);
    endpoint.setBeanFactory(this.beanFactory);
    endpoint.setId(getEndpointId(jmsListener));
    endpoint.setDestination(resolve(jmsListener.destination()));
    if (StringUtils.hasText(jmsListener.selector())) {
        endpoint.setSelector(resolve(jmsListener.selector()));
    }
    if (StringUtils.hasText(jmsListener.subscription())) {
        endpoint.setSubscription(resolve(jmsListener.subscription()));
    }
    if (StringUtils.hasText(jmsListener.concurrency())) {
        endpoint.setConcurrency(resolve(jmsListener.concurrency()));
    }
    JmsListenerContainerFactory<?> factory = null;
    String containerFactoryBeanName = resolve(jmsListener.containerFactory());
    if (StringUtils.hasText(containerFactoryBeanName)) {
        Assert.state(this.beanFactory != null, "BeanFactory must be set to obtain container factory by bean name");
        try {
            factory = this.beanFactory.getBean(containerFactoryBeanName, JmsListenerContainerFactory.class);
        } catch (NoSuchBeanDefinitionException ex) {
            throw new BeanInitializationException("Could not register JMS listener endpoint on [" + mostSpecificMethod + "], no " + JmsListenerContainerFactory.class.getSimpleName() + " with id '" + containerFactoryBeanName + "' was found in the application context", ex);
        }
    }
    this.registrar.registerEndpoint(endpoint, factory);
}
Also used : JmsListenerContainerFactory(org.springframework.jms.config.JmsListenerContainerFactory) BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) InvocableHandlerMethod(org.springframework.messaging.handler.invocation.InvocableHandlerMethod) Method(java.lang.reflect.Method) MethodJmsListenerEndpoint(org.springframework.jms.config.MethodJmsListenerEndpoint) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException)

Example 18 with NoSuchBeanDefinitionException

use of org.springframework.beans.factory.NoSuchBeanDefinitionException in project spring-boot by spring-projects.

the class EndpointWebMvcAutoConfiguration method registerServletWebServerFactory.

private void registerServletWebServerFactory(AnnotationConfigServletWebServerApplicationContext childContext) {
    try {
        ConfigurableListableBeanFactory beanFactory = childContext.getBeanFactory();
        if (beanFactory instanceof BeanDefinitionRegistry) {
            BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
            registry.registerBeanDefinition("ServletWebServerFactory", new RootBeanDefinition(determineServletWebServerFactoryClass()));
        }
    } catch (NoSuchBeanDefinitionException ex) {
    // Ignore and assume auto-configuration
    }
}
Also used : BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)

Example 19 with NoSuchBeanDefinitionException

use of org.springframework.beans.factory.NoSuchBeanDefinitionException in project spring-framework by spring-projects.

the class SimpleUrlHandlerMappingTests method handlerBeanNotFound.

@Test
public void handlerBeanNotFound() throws Exception {
    MockServletContext sc = new MockServletContext("");
    XmlWebApplicationContext root = new XmlWebApplicationContext();
    root.setServletContext(sc);
    root.setConfigLocations(new String[] { "/org/springframework/web/servlet/handler/map1.xml" });
    root.refresh();
    XmlWebApplicationContext wac = new XmlWebApplicationContext();
    wac.setParent(root);
    wac.setServletContext(sc);
    wac.setNamespace("map2err");
    wac.setConfigLocations(new String[] { "/org/springframework/web/servlet/handler/map2err.xml" });
    try {
        wac.refresh();
        fail("Should have thrown NoSuchBeanDefinitionException");
    } catch (FatalBeanException ex) {
        NoSuchBeanDefinitionException nestedEx = (NoSuchBeanDefinitionException) ex.getCause();
        assertEquals("mainControlle", nestedEx.getBeanName());
    }
}
Also used : XmlWebApplicationContext(org.springframework.web.context.support.XmlWebApplicationContext) FatalBeanException(org.springframework.beans.FatalBeanException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) MockServletContext(org.springframework.mock.web.test.MockServletContext) Test(org.junit.Test)

Example 20 with NoSuchBeanDefinitionException

use of org.springframework.beans.factory.NoSuchBeanDefinitionException in project spring-framework by spring-projects.

the class TestValidator method stompBrokerRelay.

@Test
public void stompBrokerRelay() {
    loadBeanDefinitions("websocket-config-broker-relay.xml");
    HandlerMapping hm = this.appContext.getBean(HandlerMapping.class);
    assertNotNull(hm);
    assertThat(hm, Matchers.instanceOf(SimpleUrlHandlerMapping.class));
    SimpleUrlHandlerMapping suhm = (SimpleUrlHandlerMapping) hm;
    assertThat(suhm.getUrlMap().keySet(), Matchers.hasSize(1));
    assertThat(suhm.getUrlMap().values(), Matchers.hasSize(1));
    assertEquals(2, suhm.getOrder());
    HttpRequestHandler httpRequestHandler = (HttpRequestHandler) suhm.getUrlMap().get("/foo/**");
    assertNotNull(httpRequestHandler);
    assertThat(httpRequestHandler, Matchers.instanceOf(SockJsHttpRequestHandler.class));
    SockJsHttpRequestHandler sockJsHttpRequestHandler = (SockJsHttpRequestHandler) httpRequestHandler;
    WebSocketHandler wsHandler = unwrapWebSocketHandler(sockJsHttpRequestHandler.getWebSocketHandler());
    assertNotNull(wsHandler);
    assertThat(wsHandler, Matchers.instanceOf(SubProtocolWebSocketHandler.class));
    assertNotNull(sockJsHttpRequestHandler.getSockJsService());
    UserDestinationResolver userDestResolver = this.appContext.getBean(UserDestinationResolver.class);
    assertNotNull(userDestResolver);
    assertThat(userDestResolver, Matchers.instanceOf(DefaultUserDestinationResolver.class));
    DefaultUserDestinationResolver defaultUserDestResolver = (DefaultUserDestinationResolver) userDestResolver;
    assertEquals("/user/", defaultUserDestResolver.getDestinationPrefix());
    StompBrokerRelayMessageHandler messageBroker = this.appContext.getBean(StompBrokerRelayMessageHandler.class);
    assertNotNull(messageBroker);
    assertEquals("clientlogin", messageBroker.getClientLogin());
    assertEquals("clientpass", messageBroker.getClientPasscode());
    assertEquals("syslogin", messageBroker.getSystemLogin());
    assertEquals("syspass", messageBroker.getSystemPasscode());
    assertEquals("relayhost", messageBroker.getRelayHost());
    assertEquals(1234, messageBroker.getRelayPort());
    assertEquals("spring.io", messageBroker.getVirtualHost());
    assertEquals(5000, messageBroker.getSystemHeartbeatReceiveInterval());
    assertEquals(5000, messageBroker.getSystemHeartbeatSendInterval());
    assertThat(messageBroker.getDestinationPrefixes(), Matchers.containsInAnyOrder("/topic", "/queue"));
    List<Class<? extends MessageHandler>> subscriberTypes = Arrays.<Class<? extends MessageHandler>>asList(SimpAnnotationMethodMessageHandler.class, UserDestinationMessageHandler.class, StompBrokerRelayMessageHandler.class);
    testChannel("clientInboundChannel", subscriberTypes, 2);
    testExecutor("clientInboundChannel", Runtime.getRuntime().availableProcessors() * 2, Integer.MAX_VALUE, 60);
    subscriberTypes = Collections.singletonList(SubProtocolWebSocketHandler.class);
    testChannel("clientOutboundChannel", subscriberTypes, 1);
    testExecutor("clientOutboundChannel", Runtime.getRuntime().availableProcessors() * 2, Integer.MAX_VALUE, 60);
    subscriberTypes = Arrays.<Class<? extends MessageHandler>>asList(StompBrokerRelayMessageHandler.class, UserDestinationMessageHandler.class);
    testChannel("brokerChannel", subscriberTypes, 1);
    try {
        this.appContext.getBean("brokerChannelExecutor", ThreadPoolTaskExecutor.class);
        fail("expected exception");
    } catch (NoSuchBeanDefinitionException ex) {
    // expected
    }
    String destination = "/topic/unresolved-user-destination";
    UserDestinationMessageHandler userDestHandler = this.appContext.getBean(UserDestinationMessageHandler.class);
    assertEquals(destination, userDestHandler.getBroadcastDestination());
    assertNotNull(messageBroker.getSystemSubscriptions());
    assertSame(userDestHandler, messageBroker.getSystemSubscriptions().get(destination));
    destination = "/topic/simp-user-registry";
    UserRegistryMessageHandler userRegistryHandler = this.appContext.getBean(UserRegistryMessageHandler.class);
    assertEquals(destination, userRegistryHandler.getBroadcastDestination());
    assertNotNull(messageBroker.getSystemSubscriptions());
    assertSame(userRegistryHandler, messageBroker.getSystemSubscriptions().get(destination));
    SimpUserRegistry userRegistry = this.appContext.getBean(SimpUserRegistry.class);
    assertEquals(MultiServerUserRegistry.class, userRegistry.getClass());
    String name = "webSocketMessageBrokerStats";
    WebSocketMessageBrokerStats stats = this.appContext.getBean(name, WebSocketMessageBrokerStats.class);
    String actual = stats.toString();
    String expected = "WebSocketSession\\[0 current WS\\(0\\)-HttpStream\\(0\\)-HttpPoll\\(0\\), " + "0 total, 0 closed abnormally \\(0 connect failure, 0 send limit, 0 transport error\\)\\], " + "stompSubProtocol\\[processed CONNECT\\(0\\)-CONNECTED\\(0\\)-DISCONNECT\\(0\\)\\], " + "stompBrokerRelay\\[0 sessions, relayhost:1234 \\(not available\\), processed CONNECT\\(0\\)-CONNECTED\\(0\\)-DISCONNECT\\(0\\)\\], " + "inboundChannel\\[pool size = \\d, active threads = \\d, queued tasks = \\d, completed tasks = \\d\\], " + "outboundChannelpool size = \\d, active threads = \\d, queued tasks = \\d, completed tasks = \\d\\], " + "sockJsScheduler\\[pool size = \\d, active threads = \\d, queued tasks = \\d, completed tasks = \\d\\]";
    assertTrue("\nExpected: " + expected.replace("\\", "") + "\n  Actual: " + actual, actual.matches(expected));
}
Also used : UserDestinationResolver(org.springframework.messaging.simp.user.UserDestinationResolver) DefaultUserDestinationResolver(org.springframework.messaging.simp.user.DefaultUserDestinationResolver) StompBrokerRelayMessageHandler(org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler) MessageHandler(org.springframework.messaging.MessageHandler) SimpleBrokerMessageHandler(org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler) UserRegistryMessageHandler(org.springframework.messaging.simp.user.UserRegistryMessageHandler) UserDestinationMessageHandler(org.springframework.messaging.simp.user.UserDestinationMessageHandler) SimpAnnotationMethodMessageHandler(org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler) UserRegistryMessageHandler(org.springframework.messaging.simp.user.UserRegistryMessageHandler) WebSocketHttpRequestHandler(org.springframework.web.socket.server.support.WebSocketHttpRequestHandler) SockJsHttpRequestHandler(org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler) HttpRequestHandler(org.springframework.web.HttpRequestHandler) StompBrokerRelayMessageHandler(org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler) UserDestinationMessageHandler(org.springframework.messaging.simp.user.UserDestinationMessageHandler) SimpUserRegistry(org.springframework.messaging.simp.user.SimpUserRegistry) DefaultSimpUserRegistry(org.springframework.web.socket.messaging.DefaultSimpUserRegistry) SimpleUrlHandlerMapping(org.springframework.web.servlet.handler.SimpleUrlHandlerMapping) SockJsHttpRequestHandler(org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler) SimpleUrlHandlerMapping(org.springframework.web.servlet.handler.SimpleUrlHandlerMapping) HandlerMapping(org.springframework.web.servlet.HandlerMapping) SubProtocolWebSocketHandler(org.springframework.web.socket.messaging.SubProtocolWebSocketHandler) WebSocketHandler(org.springframework.web.socket.WebSocketHandler) SubProtocolWebSocketHandler(org.springframework.web.socket.messaging.SubProtocolWebSocketHandler) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) DefaultUserDestinationResolver(org.springframework.messaging.simp.user.DefaultUserDestinationResolver) Test(org.junit.Test)

Aggregations

NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)64 Test (org.junit.Test)27 BeanCreationException (org.springframework.beans.factory.BeanCreationException)18 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)15 ConstructorArgumentValues (org.springframework.beans.factory.config.ConstructorArgumentValues)14 HashMap (java.util.HashMap)8 EventBus (org.apache.cloudstack.framework.events.EventBus)8 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)8 SimpleDateFormat (java.text.SimpleDateFormat)7 Date (java.util.Date)7 EventBusException (org.apache.cloudstack.framework.events.EventBusException)7 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)7 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)6 ConfigurableBeanFactory (org.springframework.beans.factory.config.ConfigurableBeanFactory)6 BeanFactory (org.springframework.beans.factory.BeanFactory)5 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)5 ArrayList (java.util.ArrayList)4 Account (com.cloud.user.Account)3 Method (java.lang.reflect.Method)3 ApplicationContext (org.springframework.context.ApplicationContext)3