Announcement: You can find the guides for Commerce 7.5 and later on the new Elastic Path Documentation site. The Developer Center continues to support Commerce 6.13.0 through 7.4.1.Visit new site

Registering Entity Beans

Registering Entity Beans

Elastic Path Core Commerce uses the Spring bean factory to create entity beans when required. Out-of-the-box beans are defined in core's src/main/resources/spring/prototypes/prototypes.xml. To register entity beans, you add the bean definition to your extension project's Spring configuration as described by Plug-in Architecture. If you're overriding an existing bean definition, make sure the bean id is the same as the original and that the class points to your extension class.

Warning:

Be sure to set the bean's scope attribute to prototype.

For example, prototypes.xml contains the following definition for the product bean:

<bean id="product" scope="prototype" class="com.elasticpath.domain.catalog.impl.ProductImpl"/>

Suppose you override this class with com.extensions.domain.catalog.impl.ExtProductImpl. You just need to add the following bean definition to to your extension Spring configuration:

<bean id="product" scope="prototype" class="com.extensions.domain.catalog.impl.ExtProductImpl"/>
Note: Bean Definition Clutter

Continually adding bean definitions to a single extensions Spring configuration file can lead to clutter. By using the import mechanism, you can store your custom and override bean definitions in files within a directory structure that mirrors the out-of-the-box application directory structure.

For example, to override ep-core bean definitions in resources/spring/models/domainModel.xml and resources/spring/service/service.xml file, create extension Spring configuration files in the same locations as ep-core with corresponding names that have a prefix of ext- . Then import them into ep-core-plugin.xml as follows:

<import resource="classpath*:spring/models/ext-domainModel.xml"/>
<import resource="classpath*:spring/service/ext-service.xml"/>

Note that these files should only contain your custom and overriding bean definitions. Do not include any out-of-the-box bean definitions.