Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why there are two separate xml files - <extension>-beans.xml & <extension>-spring.xml in Hybris?

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.

like image 261
AppleBud Avatar asked Dec 06 '22 17:12

AppleBud


2 Answers

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.

<bean class="de.hybris.platform.test.data.CustomerData">
    <description>Data object representing CustomerData</description>
    <property name="name" type="String"/>
    <property name="email" type="String"/>
    <property name="phone" type="String" />
</bean>

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"/>

like image 174
Free-Minded Avatar answered Dec 09 '22 14:12

Free-Minded


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.

like image 42
Mike Palfrey Avatar answered Dec 09 '22 13:12

Mike Palfrey