在没有类属性的xml中定义bean [英] Defining bean in xml without class attribute
本文介绍了在没有类属性的xml中定义bean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Spring世界的新手.在一次采访中,有人问我们是否可以在不指定class
的情况下以XML创建bean(即,该bean仅具有id
属性).我没有答案.请告知我们是否可以在Spring中使用XML创建一个bean,而无需指定class属性,以及在什么情况下通常可以这样做.
I am a newbie to the world of Spring. In an interview, it was asked if we can create a bean in XML without specifying the class
(that is, the bean would only have an id
attribute). I did not have the answer to this. Please advise if we can create a bean in XML in Spring without specifying the class attribute and under which conditions we would normally do this.
推荐答案
Spring documentation makes it quite clear:
<!--
Each bean definition must specify the fully qualified name of the class,
except if it pure serves as parent for child bean definitions.
-->
<!ATTLIST bean class CDATA #IMPLIED>
This section explains it in detail and provides useful examples.
这篇关于在没有类属性的xml中定义bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文