错误:org.springframework.beans.factory.NoSuchBeanDefinitionException:未定义名为'nimoConfigurationBean'的 b



我在Jar文件中使用Spring从属性文件中获取属性。当我从我的RAD(eclipse)尝试时,我得到了输出。但是当我在服务器上部署我的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;
    }
}

NimoConfigurationBean.java中的Getter、setter方法

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

相关内容

  • 没有找到相关文章

最新更新