Xml bean definition without class attribute

I am new to Spring. In an interview, the question was asked whether we can create a bean in XML without specifying a class (that is, a bean will only have an id attribute). I did not have an answer to this. Please advise if we can create a bean in XML in Spring without specifying a class attribute and under what conditions we usually do this.

+4
source share
2 answers

Spring documentation makes it 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 this in detail and provides useful examples.

+3
source

As described by Szymon, inheriting a bean definition is one way. Schema-based configuration is another way, see . For example, taken from the Spring documentation,

 <!-- creates a java.util.List instance with the supplied values --> <util:list id="emails"> <value> pechorin@hero.org </value> <value> raskolnikov@slums.org </value> <value> stavrogin@gov.org </value> <value> porfiry@gov.org </value> </util:list> 
0
source

All Articles