Search in sources :

Example 1 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, HttpRequestHandler> urlMap = new LinkedHashMap<>();
    for (ResourceHandlerRegistration registration : this.registrations) {
        for (String pathPattern : registration.getPathPatterns()) {
            ResourceHttpRequestHandler handler = registration.getRequestHandler();
            handler.setServletContext(this.servletContext);
            handler.setApplicationContext(this.applicationContext);
            handler.setContentNegotiationManager(this.contentNegotiationManager);
            try {
                handler.afterPropertiesSet();
            } catch (Throwable ex) {
                throw new BeanInitializationException("Failed to init ResourceHttpRequestHandler", ex);
            }
            urlMap.put(pathPattern, handler);
        }
    }
    SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping();
    handlerMapping.setOrder(order);
    handlerMapping.setUrlMap(urlMap);
    return handlerMapping;
}
Also used : BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) ResourceHttpRequestHandler(org.springframework.web.servlet.resource.ResourceHttpRequestHandler) ResourceHttpRequestHandler(org.springframework.web.servlet.resource.ResourceHttpRequestHandler) HttpRequestHandler(org.springframework.web.HttpRequestHandler) SimpleUrlHandlerMapping(org.springframework.web.servlet.handler.SimpleUrlHandlerMapping) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with BeanInitializationException

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

the class WebMvcConfigurationSupport method mvcContentNegotiationManager.

/**
	 * Return a {@link ContentNegotiationManager} instance to use to determine
	 * requested {@linkplain MediaType media types} in a given request.
	 */
@Bean
public ContentNegotiationManager mvcContentNegotiationManager() {
    if (this.contentNegotiationManager == null) {
        ContentNegotiationConfigurer configurer = new ContentNegotiationConfigurer(this.servletContext);
        configurer.mediaTypes(getDefaultMediaTypes());
        configureContentNegotiation(configurer);
        try {
            this.contentNegotiationManager = configurer.getContentNegotiationManager();
        } catch (Exception ex) {
            throw new BeanInitializationException("Could not create ContentNegotiationManager", ex);
        }
    }
    return this.contentNegotiationManager;
}
Also used : BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) Bean(org.springframework.context.annotation.Bean)

Example 3 with BeanInitializationException

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

the class FreeMarkerView method initServletContext.

/**
	 * Invoked on startup. Looks for a single FreeMarkerConfig bean to
	 * find the relevant Configuration for this factory.
	 * <p>Checks that the template for the default Locale can be found:
	 * FreeMarker will check non-Locale-specific templates if a
	 * locale-specific one is not found.
	 * @see freemarker.cache.TemplateCache#getTemplate
	 */
@Override
protected void initServletContext(ServletContext servletContext) throws BeansException {
    if (getConfiguration() != null) {
        this.taglibFactory = new TaglibFactory(servletContext);
    } else {
        FreeMarkerConfig config = autodetectConfiguration();
        setConfiguration(config.getConfiguration());
        this.taglibFactory = config.getTaglibFactory();
    }
    GenericServlet servlet = new GenericServletAdapter();
    try {
        servlet.init(new DelegatingServletConfig());
    } catch (ServletException ex) {
        throw new BeanInitializationException("Initialization of GenericServlet adapter failed", ex);
    }
    this.servletContextHashModel = new ServletContextHashModel(servlet, getObjectWrapper());
}
Also used : ServletException(javax.servlet.ServletException) BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) GenericServlet(javax.servlet.GenericServlet) ServletContextHashModel(freemarker.ext.servlet.ServletContextHashModel) TaglibFactory(freemarker.ext.jsp.TaglibFactory)

Example 4 with BeanInitializationException

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

the class ContentEnricher method doInit.

/**
 * Initializes the Content Enricher. Will instantiate an internal Gateway if the
 * requestChannel is set.
 */
@Override
protected void doInit() {
    Assert.state(!(this.requestChannelName != null && this.requestChannel != null), "'requestChannelName' and 'requestChannel' are mutually exclusive.");
    Assert.state(!(this.replyChannelName != null && this.replyChannel != null), "'replyChannelName' and 'replyChannel' are mutually exclusive.");
    Assert.state(!(this.errorChannelName != null && this.errorChannel != null), "'errorChannelName' and 'errorChannel' are mutually exclusive.");
    if (this.replyChannel != null || this.replyChannelName != null) {
        Assert.state(this.requestChannel != null || this.requestChannelName != null, "If the replyChannel is set, then the requestChannel must not be null");
    }
    if (this.errorChannel != null || this.errorChannelName != null) {
        Assert.state(this.requestChannel != null || this.requestChannelName != null, "If the errorChannel is set, then the requestChannel must not be null");
    }
    if (this.requestChannel != null || this.requestChannelName != null) {
        this.gateway = new Gateway();
        this.gateway.setRequestChannel(this.requestChannel);
        if (this.requestChannelName != null) {
            this.gateway.setRequestChannelName(this.requestChannelName);
        }
        if (this.requestTimeout != null) {
            this.gateway.setRequestTimeout(this.requestTimeout);
        }
        if (this.replyTimeout != null) {
            this.gateway.setReplyTimeout(this.replyTimeout);
        }
        this.gateway.setReplyChannel(this.replyChannel);
        if (this.replyChannelName != null) {
            this.gateway.setReplyChannelName(this.replyChannelName);
        }
        this.gateway.setErrorChannel(this.errorChannel);
        if (this.errorChannelName != null) {
            this.gateway.setErrorChannelName(this.errorChannelName);
        }
        if (this.getBeanFactory() != null) {
            this.gateway.setBeanFactory(this.getBeanFactory());
        }
        this.gateway.afterPropertiesSet();
    }
    if (this.sourceEvaluationContext == null) {
        this.sourceEvaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory());
    }
    StandardEvaluationContext targetContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory());
    // bean resolution is NOT allowed for the target of the enrichment
    targetContext.setBeanResolver(null);
    this.targetEvaluationContext = targetContext;
    if (getBeanFactory() != null) {
        boolean checkReadOnlyHeaders = getMessageBuilderFactory() instanceof DefaultMessageBuilderFactory;
        for (Map.Entry<String, HeaderValueMessageProcessor<?>> entry : this.headerExpressions.entrySet()) {
            if (checkReadOnlyHeaders && (MessageHeaders.ID.equals(entry.getKey()) || MessageHeaders.TIMESTAMP.equals(entry.getKey()))) {
                throw new BeanInitializationException("ContentEnricher cannot override 'id' and 'timestamp' read-only headers.\n" + "Wrong 'headerExpressions' [" + this.headerExpressions + "] configuration for " + getComponentName());
            }
            if (entry.getValue() instanceof BeanFactoryAware) {
                ((BeanFactoryAware) entry.getValue()).setBeanFactory(getBeanFactory());
            }
        }
        for (Map.Entry<String, HeaderValueMessageProcessor<?>> entry : this.nullResultHeaderExpressions.entrySet()) {
            if (checkReadOnlyHeaders && (MessageHeaders.ID.equals(entry.getKey()) || MessageHeaders.TIMESTAMP.equals(entry.getKey()))) {
                throw new BeanInitializationException("ContentEnricher cannot override 'id' and 'timestamp' read-only headers.\n" + "Wrong 'nullResultHeaderExpressions' [" + this.nullResultHeaderExpressions + "] configuration for " + getComponentName());
            }
            if (entry.getValue() instanceof BeanFactoryAware) {
                ((BeanFactoryAware) entry.getValue()).setBeanFactory(getBeanFactory());
            }
        }
    }
}
Also used : BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) BeanFactoryAware(org.springframework.beans.factory.BeanFactoryAware) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) DefaultMessageBuilderFactory(org.springframework.integration.support.DefaultMessageBuilderFactory) HeaderValueMessageProcessor(org.springframework.integration.transformer.support.HeaderValueMessageProcessor) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with BeanInitializationException

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

the class AbstractSimpleMessageHandlerFactoryBean method createHandlerInternal.

protected final H createHandlerInternal() {
    synchronized (this.initializationMonitor) {
        if (this.initialized) {
            // There was a problem when this method was called already
            return null;
        }
        this.handler = createHandler();
        if (this.handler instanceof ApplicationContextAware && this.applicationContext != null) {
            ((ApplicationContextAware) this.handler).setApplicationContext(this.applicationContext);
        }
        if (this.handler instanceof BeanFactoryAware && getBeanFactory() != null) {
            ((BeanFactoryAware) this.handler).setBeanFactory(getBeanFactory());
        }
        if (this.handler instanceof BeanNameAware && this.beanName != null) {
            ((BeanNameAware) this.handler).setBeanName(this.beanName);
        }
        if (this.handler instanceof ApplicationEventPublisherAware && this.applicationEventPublisher != null) {
            ((ApplicationEventPublisherAware) this.handler).setApplicationEventPublisher(this.applicationEventPublisher);
        }
        if (this.handler instanceof MessageProducer && this.outputChannel != null) {
            ((MessageProducer) this.handler).setOutputChannel(this.outputChannel);
        }
        Object actualHandler = extractTarget(this.handler);
        if (actualHandler == null) {
            actualHandler = this.handler;
        }
        if (actualHandler instanceof IntegrationObjectSupport) {
            if (this.componentName != null) {
                ((IntegrationObjectSupport) actualHandler).setComponentName(this.componentName);
            }
            if (this.channelResolver != null) {
                ((IntegrationObjectSupport) actualHandler).setChannelResolver(this.channelResolver);
            }
        }
        if (!CollectionUtils.isEmpty(this.adviceChain)) {
            if (actualHandler instanceof AbstractReplyProducingMessageHandler) {
                ((AbstractReplyProducingMessageHandler) actualHandler).setAdviceChain(this.adviceChain);
            } else if (this.logger.isDebugEnabled()) {
                String name = this.componentName;
                if (name == null && actualHandler instanceof NamedComponent) {
                    name = ((NamedComponent) actualHandler).getComponentName();
                }
                this.logger.debug("adviceChain can only be set on an AbstractReplyProducingMessageHandler" + (name == null ? "" : (", " + name)) + ".");
            }
        }
        if (this.async != null) {
            if (actualHandler instanceof AbstractMessageProducingHandler) {
                ((AbstractMessageProducingHandler) actualHandler).setAsync(this.async);
            }
        }
        if (this.handler instanceof Orderable && this.order != null) {
            ((Orderable) this.handler).setOrder(this.order);
        }
        this.initialized = true;
    }
    if (this.handler instanceof InitializingBean) {
        try {
            ((InitializingBean) this.handler).afterPropertiesSet();
        } catch (Exception e) {
            throw new BeanInitializationException("failed to initialize MessageHandler", e);
        }
    }
    return this.handler;
}
Also used : BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) ApplicationContextAware(org.springframework.context.ApplicationContextAware) IntegrationObjectSupport(org.springframework.integration.context.IntegrationObjectSupport) Orderable(org.springframework.integration.context.Orderable) ApplicationEventPublisherAware(org.springframework.context.ApplicationEventPublisherAware) NamedComponent(org.springframework.integration.support.context.NamedComponent) BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) BeansException(org.springframework.beans.BeansException) BeanNameAware(org.springframework.beans.factory.BeanNameAware) BeanFactoryAware(org.springframework.beans.factory.BeanFactoryAware) AbstractMessageProducingHandler(org.springframework.integration.handler.AbstractMessageProducingHandler) AbstractReplyProducingMessageHandler(org.springframework.integration.handler.AbstractReplyProducingMessageHandler) MessageProducer(org.springframework.integration.core.MessageProducer) InitializingBean(org.springframework.beans.factory.InitializingBean)

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