Search in sources :

Example 16 with BeanInitializationException

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

the class ViewResolverRegistry method freeMarker.

/**
 * Register a {@code FreeMarkerViewResolver} with a ".ftl" suffix.
 * <p><strong>Note</strong> that you must also configure FreeMarker by
 * adding a {@link FreeMarkerConfigurer} bean.
 */
public UrlBasedViewResolverRegistration freeMarker() {
    if (!checkBeanOfType(FreeMarkerConfigurer.class)) {
        throw new BeanInitializationException("In addition to a FreeMarker view resolver " + "there must also be a single FreeMarkerConfig bean in this web application context " + "(or its parent): FreeMarkerConfigurer is the usual implementation. " + "This bean may be given any name.");
    }
    FreeMarkerRegistration registration = new FreeMarkerRegistration();
    UrlBasedViewResolver resolver = registration.getViewResolver();
    if (this.applicationContext != null) {
        resolver.setApplicationContext(this.applicationContext);
    }
    this.viewResolvers.add(resolver);
    return registration;
}
Also used : BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) UrlBasedViewResolver(org.springframework.web.reactive.result.view.UrlBasedViewResolver) FreeMarkerConfigurer(org.springframework.web.reactive.result.view.freemarker.FreeMarkerConfigurer)

Example 17 with BeanInitializationException

use of org.springframework.beans.factory.BeanInitializationException 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 BeanInitializationException

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

the class JmsListenerEndpointRegistry method createListenerContainer.

/**
 * Create and start a new container using the specified factory.
 */
protected MessageListenerContainer createListenerContainer(JmsListenerEndpoint endpoint, JmsListenerContainerFactory<?> factory) {
    MessageListenerContainer listenerContainer = factory.createListenerContainer(endpoint);
    if (listenerContainer instanceof InitializingBean) {
        try {
            ((InitializingBean) listenerContainer).afterPropertiesSet();
        } catch (Exception ex) {
            throw new BeanInitializationException("Failed to initialize message listener container", ex);
        }
    }
    int containerPhase = listenerContainer.getPhase();
    if (containerPhase < Integer.MAX_VALUE) {
        // a custom phase value
        if (this.phase < Integer.MAX_VALUE && this.phase != containerPhase) {
            throw new IllegalStateException("Encountered phase mismatch between container factory definitions: " + this.phase + " vs " + containerPhase);
        }
        this.phase = listenerContainer.getPhase();
    }
    return listenerContainer;
}
Also used : BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) InitializingBean(org.springframework.beans.factory.InitializingBean) MessageListenerContainer(org.springframework.jms.listener.MessageListenerContainer) BeanInitializationException(org.springframework.beans.factory.BeanInitializationException)

Example 19 with BeanInitializationException

use of org.springframework.beans.factory.BeanInitializationException in project uPortal by Jasig.

the class PortalPropertySourcesPlaceholderConfigurer method postProcessBeanFactory.

/**
 * Override the postProcessing. The default PropertySourcesPlaceholderConfigurer does not inject
 * local properties into the Environment object. It builds a local list of properties files and
 * then uses a transient Resolver to resolve the @Value annotations. That means that you are
 * unable to get to "local" properties (eg. portal.properties) after bean post-processing has
 * completed unless you are going to re-parse those file. This is similar to what
 * PropertiesManager does, but it uses all the property files configured, not just
 * portal.properties.
 *
 * <p>If we upgrade to spring 4, there are better/more efficient solutions available. I'm not
 * aware of better solutions for spring 3.x.
 *
 * @param beanFactory the bean factory
 * @throws BeansException if an error occurs while loading properties or wiring up beans
 */
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    if (propertyResolver == null) {
        try {
            MutablePropertySources sources = new MutablePropertySources();
            PropertySource<?> localPropertySource = new PropertiesPropertySource(EXTENDED_PROPERTIES_SOURCE, mergeProperties());
            sources.addLast(localPropertySource);
            propertyResolver = new PropertySourcesPropertyResolver(sources);
        } catch (IOException e) {
            throw new BeanInitializationException("Could not load properties", e);
        }
    }
    super.postProcessBeanFactory(beanFactory);
}
Also used : PropertySourcesPropertyResolver(org.springframework.core.env.PropertySourcesPropertyResolver) BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) PropertiesPropertySource(org.springframework.core.env.PropertiesPropertySource) MutablePropertySources(org.springframework.core.env.MutablePropertySources) IOException(java.io.IOException)

Example 20 with BeanInitializationException

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

the class ResourceHandlerRegistry method getHandlerMapping.

/**
	 * Return a handler mapping with the mapped resource handlers; or {@code null} in case
	 * of no registrations.
	 */
protected AbstractHandlerMapping getHandlerMapping() {
    if (this.registrations.isEmpty()) {
        return null;
    }
    Map<String, WebHandler> urlMap = new LinkedHashMap<>();
    for (ResourceHandlerRegistration registration : this.registrations) {
        for (String pathPattern : registration.getPathPatterns()) {
            ResourceWebHandler handler = registration.getRequestHandler();
            handler.setContentTypeResolver(this.contentTypeResolver);
            try {
                handler.afterPropertiesSet();
                handler.afterSingletonsInstantiated();
            } catch (Exception ex) {
                throw new BeanInitializationException("Failed to init ResourceHttpRequestHandler", ex);
            }
            urlMap.put(pathPattern, handler);
        }
    }
    SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping();
    handlerMapping.setOrder(this.order);
    handlerMapping.setUrlMap(urlMap);
    return handlerMapping;
}
Also used : BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) WebHandler(org.springframework.web.server.WebHandler) ResourceWebHandler(org.springframework.web.reactive.resource.ResourceWebHandler) ResourceWebHandler(org.springframework.web.reactive.resource.ResourceWebHandler) BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) SimpleUrlHandlerMapping(org.springframework.web.reactive.handler.SimpleUrlHandlerMapping) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

BeanInitializationException (org.springframework.beans.factory.BeanInitializationException)41 IOException (java.io.IOException)9 BeansException (org.springframework.beans.BeansException)7 HashMap (java.util.HashMap)4 Bean (org.springframework.context.annotation.Bean)4 File (java.io.File)3 Method (java.lang.reflect.Method)3 Properties (java.util.Properties)3 Field (java.lang.reflect.Field)2 Connection (java.sql.Connection)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Matcher (java.util.regex.Matcher)2 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)2 PropertyValue (org.springframework.beans.PropertyValue)2 BeanDefinitionStoreException (org.springframework.beans.factory.BeanDefinitionStoreException)2 BeanFactoryAware (org.springframework.beans.factory.BeanFactoryAware)2