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