on ‎2018 Jan 30 5:45 PM
I'm working with Hybris 6.2, and I need to customize some of the resources that are generated from my items.
I've read this link, and this link, but I am unable to make my custom resource to be used.
My resource is located in myextension\custom\src\de\hybris\platform\yacceleratorcore\customresource as indicated in the mentioned wiki guide, and so far looks like this:
package de.hybris.platform.yacceleratorcore.customresource;
import de.hybris.platform.webservices.AbstractYResource;
import de.hybris.platform.yacceleratorcore.model.SparepartsModel;
import org.apache.log4j.Logger;
@SuppressWarnings("PMD")
public class CustomSparepartsResource extends AbstractYResource<SparepartsModel>
{
private static final Logger LOG = Logger.getLogger(CustomSparepartsResource.class);
public CustomSparepartsResource()
{
super("CustomSpareparts");
}
@Override
protected SparepartsModel readResource(final String resourceId) throws Exception
{
final SparepartsModel model = new SparepartsModel();
model.setCode(resourceId);
LOG.debug("Custom resource");
return (SparepartsModel) readResourceInternal(model);
}
}
I'm trying to just print that log message just as a start, but this resource is not being used instead of the default one that is generated on each ant clean all.
I have this resource bean defined in my customplatformwebservices-web-spring.xml as follows:
<bean id="customSparepartsResource" class="de.hybris.platform.yacceleratorcore.customresource.CustomSparepartsResource" scope="prototype" parent="abstractResource"/>
But when I start the server, I get the following error message:
[1;31mERROR [localhost-startStop-1] [ContextLoader] Context initialization failed [m org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [de.hybris.platform.yacceleratorcore.customresource.CustomSparepartsResource] for bean with name 'customSparepartsResource' defined in class path resource [customplatformwebservices-web-spring.xml]; nested exception is java.lang.ClassNotFoundException: de.hybris.platform.yacceleratorcore.customresource.CustomSparepartsResource
What am I missing on my implementation? How can I successfully replace the generated resource with my own custom resource?
Request clarification before answering.
I finally found the way to do it for my Hybris version 6.2, first I need to name my resource the same name as the one I want to replace, that way the default one won't be generated, instead my custom resource will be placed under web/gensrc.
For my version, there's no need to add the bean definition into myextension-web-spring.xml.
With this there should not be any problem to use your own custom resources.
As a side note, if you require the use of services and dao classes in your resources, don't put them in your custom extension, since once your custom resources are copied to platformwebservices, then they won't be able to see these classes unless you define them in a different extension that's not requiring platformwebservices already.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Maybe you need to add the bean definition of CustomSparepartsResource to customplatformwebservices-web-spring.xml instead to your web-spring.xml file, as it is somehow mentioned in the log you provided. In the wiki i see that they mentioned the web-spring.xml file, but I think that is actually meant: your_extension_name-web-spring.xml
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.