cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to customize a platformwebservices resource?

Former Member
0 Likes
533

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:

ERROR [localhost-startStop-1] [ContextLoader] Context initialization failed  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?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Likes

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.

Answers (1)

Answers (1)

Former Member
0 Likes

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

Former Member
0 Likes

I did, that's the only web-srping.xml file in my custom extension.