0

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 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?

Uriel Arvizu
  • 1,876
  • 6
  • 37
  • 97

2 Answers2

0

It is not a good idea to use de.hybris.platform as a namespace for your custom extension. This in the wiki is just an example. Use your own namespace because this way you might get a lot of other spring errors.

Also everything you change in /platform folders, extension, gets regenerated after a build/update/ . Every time be sure to create your own extensions with your own namespace and not using the default hybris ones.

Hristo Staykov
  • 939
  • 7
  • 13
  • I mentioned in my question I'm using my own extension for this customization, as for the package that's how our client created their items, thanks for the observations – Uriel Arvizu Jan 31 '18 at 17:43
0

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.

Uriel Arvizu
  • 1,876
  • 6
  • 37
  • 97