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