2015-01-09 60 views
0

錯誤,我得到了以下異常而運行我的Spring應用程序:春:豆混淆

Jan 09, 2015 2:47:33 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 
INFO: Loading XML bean definitions from class path resource [com/amscoder/ba/common/application-context.xml] 
Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'agent' is defined 
     at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:570) 
     at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1114) 
     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:279) 
     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198) 
     at com.amscoder.ba.test.RobotTest.main(RobotTest.java:15) 

我的Spring bean配置文件是: 「應用程序的context.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" 
xsi:schemaLocation=" 
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> 
<bean id="robot" class="com.amscoder.ba.beans.Robot"> 
    <property name="id" value="101" /> 
    <property name="name" value="Robot-1" /> 
</bean> 

<alias name="agent" alias="robot" /> 

其實我想給我的bean多個名字。
任何人都可以幫助我解決錯誤。

回答

3

試試這個:

<alias name="robot" alias="agent" /> 

注:agent是別名,不robot

+0

感謝@ Jaiwo99。 – Ashrumochan