Example usage for org.springframework.beans.factory BeanInitializationException BeanInitializationException

List of usage examples for org.springframework.beans.factory BeanInitializationException BeanInitializationException

Introduction

In this page you can find the example usage for org.springframework.beans.factory BeanInitializationException BeanInitializationException.

Prototype

public BeanInitializationException(String msg) 

Source Link

Document

Create a new BeanInitializationException with the specified message.

Usage

From source file:org.springframework.ws.test.support.MockStrategiesHelper.java

/**
 * Returns a single strategy found in the given application context.
 *
 * @param type the type of bean to be found in the application context
 * @return the bean, or {@code null} if no bean of the given type can be found
 * @throws BeanInitializationException if there is more than 1 beans of the given type
 *///  ww  w.j  av a2  s.  c om
public <T> T getStrategy(Class<T> type) {
    Assert.notNull(type, "'type' must not be null");
    Map<String, T> map = applicationContext.getBeansOfType(type);
    if (map.isEmpty()) {
        return null;
    } else if (map.size() == 1) {
        Map.Entry<String, T> entry = map.entrySet().iterator().next();
        if (logger.isDebugEnabled()) {
            logger.debug("Using " + ClassUtils.getShortName(type) + " [" + entry.getKey() + "]");
        }
        return entry.getValue();
    } else {
        throw new BeanInitializationException(
                "Could not find exactly 1 " + ClassUtils.getShortName(type) + " in application context");
    }
}

From source file:ro.cs.cm.web.common.MultiFormBeanCheckingInterceptor.java

/**
* Set to store the data./*from  ww  w  .ja v a 2 s.c o m*/
*
* @param controllers
*           A Map containing the revelant controllers as keys and name of
*           the property on then that returns the view name as the value.
*/
public void setControllers(Map<K, String> controllers) {

    // Loop through the passed controllers and assemble the data.
    String viewName;
    for (K c : controllers.keySet()) {

        this.logger.debug("Setting controller form bean for " + c.getCommandName());

        if (!c.isSessionForm()) {
            throw new BeanInitializationException("Controller is not set for session beans.");
        }

        // get the view name.
        try {
            viewName = this.getViewName((String) controllers.get(c));
            this.logger.debug(viewName + " => bean " + c.getCommandClass().getName());
        } catch (Exception e) {
            throw new BeanInitializationException("Could not extract view name from controller", e);
        }

        // Check and create a vector for it .
        if (!this.controllers.containsKey(viewName)) {
            this.controllers.put(viewName, new Vector<K>());
        }

        // Now add the controller to the list,
        this.controllers.get(viewName).add(c);
    }
}