2014-03-18 50 views
0

我在我的Jar文件中使用Spring從屬性文件中獲取屬性。當我從我的RAD(日食)中嘗試時,我會得到輸出。但是當我在服務器上部署我的jar文件時,我不斷收到此錯誤。錯誤:org.springframework.beans.factory.NoSuchBeanDefinitionException:沒有定義名爲'nimoConfigurationBean'的bean

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) 

當我得到出現的錯誤豆:

**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中添加點數

+1

你確定你的配置文件在你的類路徑中嗎? – Zeki

回答

-1

如果bean可配置的源在加載時不可用,Spring容器將引發NoSuchBeanDefinitionException。在你的情況下,可配置的源代碼是XML,即你的應用程序上下文xml不適用於spring。確保您的XML已打包並可用於類路徑。

+0

在我以前沒有找到XML,但添加類路徑(如「classpath *:/ com/xml/* applicationContext.xml」)後,錯誤消失了,現在我收到了bean錯誤。 – user3407089

相關問題