gpt4 book ai didi

java - Spring:Bean 别名错误

转载 作者:行者123 更新时间:2023-12-01 22:30:35 25 4
gpt4 key购买 nike

运行 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配置文件是:“application-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 指定多个名称。
谁能帮我解决这个错误。

最佳答案

试试这个:

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

注意:agent是别名,而不是robot

关于java - Spring:Bean 别名错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27857485/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com