错误:org.springframework.beans.factory.NoSuchBeanDefinitionException:没有名为' nimoConfigurationBean的bean'被定义为

时间:2014-03-18 20:59:40

标签: java eclipse spring frameworks rad

我在Jar文件中使用Spring从属性文件中获取属性。当我尝试从我的RAD(日食)时,我得到输出。但是当我在服务器中部署我的jar文件时,我不断收到此错误。

ERROR:

Exception 
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'nimoConfigurationBean' is defined
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:509)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1041)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:273)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1044)

当我得到bean时发生错误:

**NimoConfigurationBean obj = (NimoConfigurationBean) context.getBean("nimoConfigurationBean");**

XML:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:jee="http://www.springframework.org/schema/jee"
       xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="http://www.springframework.org/schema/util http://xml.westfieldgrp.com/public/schema/util/spring-util-3.0.xsd
                           http://www.springframework.org/schema/beans http://xml.westfieldgrp.com/public/schema/beans/spring-beans-3.0.xsd 
                           http://www.springframework.org/schema/jee http://xml.westfieldgrp.com/public/schema/jee/spring-jee-3.0.xsd" >    
    <bean id="applicationProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="classpath:/config/devint/nimo.properties"/>
    </bean>  
    <bean id="nimoConfigurationBean" scope="singleton"
        class="com.westfieldgrp.filenet.env.NimoConfigurationBean">
        <property name="serviceUser" value="${env.user}" />
        <property name="servicePass" value="${env.pass}" />
    </bean> 
</beans>

使用Java调用:     公共类AddEnvProperty {

             public String envType(String propertyValue) {  
        String returnValue = "";

        AddEnvProperty envProps = new AddEnvProperty();
        NimoConfigurationBean nimoConfigurationBean = envProps.getConfig();

        PluginLogger logger = new PluginLogger(new ResponceFilterPlugin());
        logger.logDebug(this, "envType", "Getting Property Value" + propertyValue);
        try {

             if (propertyValue == "USER") {
                returnValue = nimoConfigurationBean.getServiceUser();
            } else if (propertyValue == "PASS") {
                returnValue = nimoConfigurationBean.getServicePass();
            }

        } catch (NullPointerException ex) {
            // TODO Auto-generated catch block
            logger.logError(this, "envType", "NullPointerException:", ex);
        }catch (Exception ex) {
            // TODO Auto-generated catch block
            logger.logError(this, "envType", "NullPointerException:", ex);
        }
        return returnValue;
    }

    private NimoConfigurationBean getConfig() {
       ApplicationContext context = 
            new ClassPathXmlApplicationContext("classpath*:/com/xml/*applicationContext.xml");

        NimoConfigurationBean obj = (NimoConfigurationBean) context.getBean("nimoConfigurationBean");
        return obj;
    }
}

Getter,NimoConfigurationBean.java中的setter方法

1 个答案:

答案 0 :(得分:-1)

如果Bean可配置源在加载时不可用,则Spring容器会抛出NoSuchBeanDefinitionException。在您的情况下,可配置的源是XML,即您的应用程序上下文xml不可用于spring。确保您的XML已打包并可用于类路径。