Example usage for org.springframework.beans.factory BeanDefinitionStoreException getMessage

List of usage examples for org.springframework.beans.factory BeanDefinitionStoreException getMessage

Introduction

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

Prototype

@Override
@Nullable
public String getMessage() 

Source Link

Document

Return the detail message, including the message from the nested exception if there is one.

Usage

From source file:fr.paris.lutece.plugins.workflow.modules.mappings.business.CodeMappingFactory.java

/**
 * {@inheritDoc}/* w ww .j  a  v  a2 s .c om*/
 */
@Override
public ICodeMapping newCodeMapping(String strMappingTypeKey) {
    ICodeMapping codeMapping = null;

    try {
        codeMapping = SpringContextService.getBean(strMappingTypeKey);
    } catch (BeanDefinitionStoreException e) {
        AppLogService.debug("CodeMappingFactory ERROR : could not load bean '" + e.getBeanName()
                + "' - CAUSE : " + e.getMessage());
    } catch (NoSuchBeanDefinitionException e) {
        AppLogService.debug("CodeMappingFactory ERROR : could not load bean '" + e.getBeanName()
                + "' - CAUSE : " + e.getMessage());
    } catch (CannotLoadBeanClassException e) {
        AppLogService.debug("CodeMappingFactory ERROR : could not load bean '" + e.getBeanName()
                + "' - CAUSE : " + e.getMessage());
    }

    // If no mapping type is defined for strMappingTypeKey, then create a SimpleMappingType
    if (codeMapping == null) {
        codeMapping = new SimpleCodeMapping();
    }

    return codeMapping;
}

From source file:org.ff4j.spring.placeholder.FF4jPropertiesPlaceHolderConfigurer.java

/** {@inheritDoc} */
public final void postProcessBeanFactory(final ConfigurableListableBeanFactory beanFactory) {
    try {//from   www  .  ja v  a 2  s . co  m
        // 1) Retrieve properties from ff4j
        BeanDefinitionVisitor visitor = new PropertiesPlaceHolderBeanDefinitionVisitor(ff4j);

        // 2) Inject property & features value
        String[] beanNames = beanFactory.getBeanDefinitionNames();
        for (int i = 0; i < beanNames.length; i++) {
            if (beanNames[i].equals(beanName)) {
                continue;
            }
            BeanDefinition bd = beanFactory.getBeanDefinition(beanNames[i]);
            try {
                visitor.visitBeanDefinition(bd);
            } catch (BeanDefinitionStoreException ex) {
                throw new BeanDefinitionStoreException(bd.getResourceDescription(), beanNames[i],
                        ex.getMessage());
            }
        }
    } catch (Exception e) {
        LOGGER.error("Cannot handle placeholding through ff4j : ", e);
        throw new BeanInitializationException("An error occured during substition", e);
    }
}

From source file:com.photon.phresco.configuration.XmlPropertyPlaceholderConfigurer.java

@Override
protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props)
        throws BeansException {

    org.springframework.util.StringValueResolver valueResolver = new PlaceholderResolvingStringValueResolver(
            props);/*from   w  ww . ja  v  a  2  s .  com*/
    org.springframework.beans.factory.config.BeanDefinitionVisitor visitor = new org.springframework.beans.factory.config.BeanDefinitionVisitor(
            valueResolver);

    String[] beanNames = beanFactoryToProcess.getBeanDefinitionNames();
    for (int i = 0; i < beanNames.length; i++) {
        // Check that we're not parsing our own bean definition,
        // to avoid failing on unresolvable placeholders in properties file locations.
        if (!(beanNames[i].equals(this.beanName) && beanFactoryToProcess.equals(this.beanFactory))) {
            BeanDefinition bd = beanFactoryToProcess.getBeanDefinition(beanNames[i]);
            try {
                visitor.visitBeanDefinition(bd);
            } catch (BeanDefinitionStoreException ex) {
                throw new BeanDefinitionStoreException(bd.getResourceDescription(), beanNames[i],
                        ex.getMessage());
            }
        }
    }

    // New in Spring 2.5: resolve placeholders in alias target names and aliases as well.
    beanFactoryToProcess.resolveAliases(valueResolver);
}

From source file:fr.paris.lutece.plugins.mylutece.modules.database.authentication.business.DatabaseUserFactory.java

/**
* Instanciate a new {@link DatabaseUser} defined in <b>database_context.xml</b>
* @return a new instance of {@link DatabaseUser}
*///w  ww .jav a 2s. c om
public DatabaseUser newDatabaseUser() {
    DatabaseUser databaseUser = null;

    try {
        databaseUser = (DatabaseUser) SpringContextService.getBean(_strBeanDatabaseUser);
    } catch (BeanDefinitionStoreException e) {
        if (AppLogService.isDebugEnabled()) {
            AppLogService.debug("DatabaseUserFactory ERROR : could not load bean '" + e.getBeanName()
                    + "' - CAUSE : " + e.getMessage());
        }
    } catch (NoSuchBeanDefinitionException e) {
        if (AppLogService.isDebugEnabled()) {
            AppLogService.debug("DatabaseUserFactory ERROR : could not load bean '" + e.getBeanName()
                    + "' - CAUSE : " + e.getMessage());
        }
    } catch (CannotLoadBeanClassException e) {
        if (AppLogService.isDebugEnabled()) {
            AppLogService.debug("DatabaseUserFactory ERROR : could not load bean '" + e.getBeanName()
                    + "' - CAUSE : " + e.getMessage());
        }
    }

    // New DatabaseUser by default if the plugin cannot load the DatabaseUser by Spring 
    if (databaseUser == null) {
        databaseUser = new DatabaseUser();
    }

    return databaseUser;
}

From source file:fr.paris.lutece.plugins.workflow.service.task.TaskFactory.java

/**
 * {@inheritDoc}//from   w  w w  .java2  s  .  c  o  m
 */
@Override
public ITaskConfig newTaskConfig(String strKey) {
    if (StringUtils.isBlank(strKey)) {
        AppLogService.error("TaskFactory ERROR : The key is empty.");

        return null;
    }

    Collection<ITaskType> listTaskType = getAllTaskTypes();

    for (ITaskType taskType : listTaskType) {
        if (strKey.equals(taskType.getKey())) {
            try {
                ITaskConfig config = SpringContextService.getBean(taskType.getConfigBeanName());

                return config;
            } catch (BeanDefinitionStoreException e) {
                AppLogService.error("TaskFactory ERROR : could not load bean '" + e.getBeanName()
                        + "' - CAUSE : " + e.getMessage(), e);
            } catch (NoSuchBeanDefinitionException e) {
                AppLogService.error("TaskFactory ERROR : could not load bean '" + e.getBeanName()
                        + "' - CAUSE : " + e.getMessage(), e);
            } catch (CannotLoadBeanClassException e) {
                AppLogService.error("TaskFactory ERROR : could not load bean '" + e.getBeanName()
                        + "' - CAUSE : " + e.getMessage(), e);
            }
        }
    }

    AppLogService.error("TaskFactory ERROR : The task type is not found.");

    return null;
}

From source file:fr.paris.lutece.plugins.workflow.service.task.TaskFactory.java

/**
 * Get new instance of {@link ITask}/*from  w ww  . ja va  2s.  com*/
 * @param strKey the task type key
 * @return a new instance of {@link ITask}
 */
private ITask newTask(String strKey) {
    if (StringUtils.isBlank(strKey)) {
        AppLogService.error("TaskFactory ERROR : The key is empty.");

        return null;
    }

    Collection<ITaskType> listTaskType = getAllTaskTypes();

    for (ITaskType taskType : listTaskType) {
        if (strKey.equals(taskType.getKey())) {
            try {
                ITask task = SpringContextService.getBean(taskType.getBeanName());
                task.setTaskType(taskType);

                return task;
            } catch (BeanDefinitionStoreException e) {
                AppLogService.error("TaskFactory ERROR : could not load bean '" + e.getBeanName()
                        + "' - CAUSE : " + e.getMessage(), e);
            } catch (NoSuchBeanDefinitionException e) {
                AppLogService.error("TaskFactory ERROR : could not load bean '" + e.getBeanName()
                        + "' - CAUSE : " + e.getMessage(), e);
            } catch (CannotLoadBeanClassException e) {
                AppLogService.error("TaskFactory ERROR : could not load bean '" + e.getBeanName()
                        + "' - CAUSE : " + e.getMessage(), e);
            }
        }
    }

    AppLogService.error("TaskFactory ERROR : The task type is not found.");

    return null;
}

From source file:com.devbury.desktoplib.spring.LogFilterPropertyPlaceholderConfigurer.java

public void postProcessBeanFactory(ConfigurableListableBeanFactory bf) throws BeansException {
    BeanDefinitionVisitor visitor = newVisitor();
    String[] beanNames = bf.getBeanDefinitionNames();
    for (int i = 0; i < beanNames.length; i++) {
        // Check that we're not parsing our own bean definition,
        // to avoid failing on unresolvable placeholders in properties file
        // locations.
        if (!(beanNames[i].equals(beanName))) {
            BeanDefinition bd = bf.getBeanDefinition(beanNames[i]);
            try {
                visitor.visitBeanDefinition(bd);
            } catch (BeanDefinitionStoreException ex) {
                throw new BeanDefinitionStoreException(bd.getResourceDescription(), beanNames[i],
                        ex.getMessage());
            }//from ww w . ja  va  2  s .co m
        }
    }
}

From source file:com.apporiented.spring.override.AbstractGenericBeanDefinitionParser.java

public final BeanDefinition parse(Element element, ParserContext parserContext) {
    if (!enabled) {
        throw new FatalBeanException("Support for " + element.getTagName()
                + " has been disabled. Please add the required jar files " + "to your classpath.");
    }//from w ww  .  java  2  s.c  o m
    AbstractBeanDefinition definition = parseInternal(element, parserContext);
    if (!parserContext.isNested()) {
        try {
            String id = resolveId(element, definition, parserContext);
            if (!StringUtils.hasText(id)) {
                parserContext.getReaderContext().error("Id is required for element '" + element.getLocalName()
                        + "' when used as a top-level tag", element);
            }
            String[] aliases = resolveAliases(element, definition, parserContext);
            BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, id, aliases);
            if (decorator != null) {
                holder = decorator.decorate(element, holder, parserContext);
            }
            registerBeanDefinition(holder, parserContext.getRegistry());
            if (shouldFireEvents()) {
                BeanComponentDefinition componentDefinition = new BeanComponentDefinition(holder);
                postProcessComponentDefinition(componentDefinition);
                parserContext.registerComponent(componentDefinition);
            }
        } catch (BeanDefinitionStoreException ex) {
            parserContext.getReaderContext().error(ex.getMessage(), element);
            return null;
        }
    } else if (decorator != null) {
        BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, "");
        decorator.decorate(element, holder, parserContext);
    }
    return definition;
}

From source file:org.springframework.beans.factory.xml.XmlBeanFactoryTests.java

/**
 * Check that a prototype can't inherit from a bogus parent.
 * If a singleton does this the factory will fail to load.
 */// ww w  .j  a  v  a 2s .  c o  m
@Test
public void testBogusParentageFromParentFactory() throws Exception {
    DefaultListableBeanFactory parent = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT);
    DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
    new XmlBeanDefinitionReader(child).loadBeanDefinitions(CHILD_CONTEXT);
    try {
        child.getBean("bogusParent", TestBean.class);
        fail();
    } catch (BeanDefinitionStoreException ex) {
        // check exception message contains the name
        assertTrue(ex.getMessage().indexOf("bogusParent") != -1);
        assertTrue(ex.getCause() instanceof NoSuchBeanDefinitionException);
    }
}

From source file:org.springframework.beans.factory.xml.XmlBeanFactoryTests.java

@Test
public void testRejectsOverrideOfBogusMethodName() {
    DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
    try {//from   w  ww.j a  va 2 s .c om
        reader.loadBeanDefinitions(INVALID_NO_SUCH_METHOD_CONTEXT);
        xbf.getBean("constructorOverrides");
        fail("Shouldn't allow override of bogus method");
    } catch (BeanDefinitionStoreException ex) {
        // Check that the bogus method name was included in the error message
        assertTrue("Bogus method name correctly reported", ex.getMessage().indexOf("bogusMethod") != -1);
    }
}