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 Non-Entity Beans

Registering Non-Entity Beans

To register a non-entity beans, you add the bean definition to your extension project 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.

For example, ep-core/src/main/resources/spring/service/service.xml contains the following bean definition for productXmlService:

<bean id="productXmlService" class="com.elasticpath.service.catalog.impl.ProductXmlServiceImpl">
    <property name="productLookup" ref="productLookup"/>
    <property name="categoryLookup" ref="categoryLookup"/>
    <property name="beanFactory" ref="coreBeanFactory"/>
</bean>

You have overridden this with this custom class com.elasticpath.extensions.service.catalog.impl.ExtProductXmlServiceImpl. To enable your overridden service, you need to add the following bean definition to your core extension:

<bean id="productXmlService" class="com.elasticpath.service.catalog.impl.ExtProductXmlServiceImpl">
    <property name="productLookup" ref="productLookup"/>
    <property name="categoryLookup" ref="categoryLookup"/>
    <property name="beanFactory" ref="coreBeanFactory"/>
</bean>
Note:

If your service only applies to a specific module project, you only need to add it to that module's ep-<module>-plugin.xml.

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.