Java: is it good practice to define beans in XML? -
in project i'm working on, using spring, see boggles mind. apparently there unit tests need beans work , beans created xml files, containing things like:
<bean class="...listdto"> <constructor-arg> <map> <entry key="use1key"> <value>use1value</value> </entry> <entry key="use2key"> <value>use2value</value> </entry> </map> </constructor-arg> <constructor-arg> <map> <entry key="nature1key"> <value>nature1value</value> </entry> <entry key="nature2key"> <value>nature2value</value> </entry> </map> </constructor-arg> <constructor-arg> <value>false</value> </constructor-arg> </bean>
and did happen? constructor of class ...listdto changed , hence bean apparently cannot created anymore (very verbose imho) xml.
can explain me why practice (is really?) put such thing in xml instead of java code? if in java code, ...listdto have changed unit test have refused compile (even if part of unit test instantiating bean didn't executed [for whatever reason]).
bonus question: there way find these broken "beans in xml" in project besides running unit tests, see ones failing , rinse-and-repeating?
to me seems pretty serious issue can change constructor , ide act if fine: justification this? (*)
the idea behind keep things differ between environments (development, testing, production) in central xml configuration file, , using different config file, switch environments.
however, it's not practice use bean configuration define complex test data structures. did while newly enamoured dependency injection, because it's possible.
Comments
Post a Comment