Reputation: 157
When to define bean on *-spring.xml and *-beans.xml in Hybris? What is the difference between them?
Upvotes: 3
Views: 6575
Reputation: 1311
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).
-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.ProductData">
<description>Data object representing ProductData</description>
<property name="code" type="Long"/>
<property name="name" type="String"/>
<property name="price" type="Double"/>
</bean>
Converter/Populators are being used to populate the DTO.
-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"/>
Beans declared in a *spring.xml file are not auto generated.
Upvotes: 1
Reputation: 658
E.g. you define a new entity Color to store it in your DB.
To define spring beans such as ColorDao or ColorService you will use yourextension-spring.xml.
In ColorDao or ColorService you work with model classes. In this case, it will be ColorModel, but when it comes to writing a ColorFacade you can't expose your model classes to outside world and you need to convert it to some DTO. So you go to yourextension-beans.xml and create there ColorData class.
ColorData is generated from yourextension-beans.xml during ant all.
Upvotes: 7