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

This version of Elastic Path Commerce is no longer supported or maintained. To upgrade to the latest version, contact your Elastic Path representative.

Registering non-entity beans

Registering non-entity beans

To register a non-entity beans, you add the bean definition to your extension project's <webapp>-plugin.xml, located in src/main/resources/META-INF/conf. 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:

            core/ep-core/src/main/resources/spring/service/service.xml
	<bean id="productXmlService" class="com.elasticpath.service.catalog.impl.ProductXmlServiceImpl">
		<property name="productLookup" ref="productLookup"/commerce-legacy/>
		<property name="categoryLookup" ref="categoryLookup"/commerce-legacy/>
		<property name="beanFactory" ref="coreBeanFactory"/commerce-legacy/>
	</bean>

         

You have overridden this with this custom class com.extensions.service.catalog.impl.MyProductXmlServiceImpl. To enable your overridden service, you need to add the following bean definition to the ep-core-plugin.xml of your core extension:

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

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

Note: Bean Definition Clutter

Continually adding bean definitions to <webapp>-plugin.xml 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. For example, to override, bean definitions in storefront's serviceSF.xml and url-mapping.xml, recreate the directory structure of the OOTB project under conf and create Spring configuration files with the same names in the appropriate locations. Then import them into ep-storefront-plugin.xml as follows:

    ...
    <import resource="classpath*:spring/service/serviceSF.xml"/commerce-legacy/>
    <import resource="classpath*:spring/web/url-mapping.xml"/commerce-legacy/>
    ...
</beans>

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