I am new to Hybris and was little confused about the structure of an extension in it. Whenever we create any extension, it contains two XML files : -beans.xml and -spring.xml
<extension>-beans.xml
file contains definition for beans and their attributes or in other words, the DTOs.
<extension>-spring.xml
also contains definition for some beans and their attributes.
This is what I understood so far. Please correct me if I am wrong.
When we can define beans in spring.xml
, why there is a need for another XML file "beans.xml
" ?
Please provide some clarification on this. Thanks.
As we know Hybris is following layered architecture where we are fetching the data from the persistence layer (Database) in the form of Model and send the result to presentation layer in the form of DTO (data transfer object).
<extension>-beans.xml
-We create the Data objects in a declarative way, for eg define beans and enumerations in an xml file used as input for code generating. The main advantage is that you can merge attributes over several extensions
In short to create DTO, we are using -beans.xml which will then be used in controller to show the result in jsp.
Converter/Populators are being used to populate the DTO.
<extension>-spring.xml
-This file is used to defined your class beans (like facade, service, dao, strategy etc).
<bean id="defaultProductService" class="de.com.test.DefaultProductService"/>
Typically the *beans.xml files in Hybris are used to represent a data model (like has been mentioned above). These files are read by the platform and from this, the DTOs are auto generated.
Beans declared in a *spring.xml file are not auto generated.
https://wiki.hybris.com/display/release5/Generating+Beans+and+Enums has some more information on this.