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;
}
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;
}
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());
}
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());
}
}
}
}
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;
}
Aggregations