Why there are two separate xml files -

2019-05-10 03:01发布

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.

标签: java hybris
2条回答
乱世女痞
2楼-- · 2019-05-10 03:28

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

查看更多
男人必须洒脱
3楼-- · 2019-05-10 03:35

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.

查看更多
登录 后发表回答