Question

In hybris, is there an easy way to know which implementing class is being used for a certain Spring bean?

I mean, I can override a Bean by doing something like this:

<alias name="myCheckoutFacade" alias="checkoutFacade"/>
<bean id="myCheckoutFacade" class="com.pedra.facades.checkout.impl.MyCheckoutFacadeImpl" scope="tenant" parent="defaultCheckoutFacade">
    <property name="commerceCheckoutService" ref="myCommerceCheckoutService"/>
</bean>

... so now when Spring needs to create a bean with the alias checkoutFacade the implementing class will be MyCheckoutFacadeImpl as opposed to the overridden defaultCheckoutFacade which was defined in some other xml configuration file.

So is there a way to know at runtime which implementing class is being used for a certain Spring bean definition? Without having to debug the code, I mean.

Was it helpful?

Solution

Beanshell or Groovy :-)

Checking the implementing class of a bean is just one of the many cool things you can do at runtime with Beanshell or Groovy.

Disclaimer: Be careful running Beanshell or Groovy code on a production machine!

  • Log in to the HAC and go to Console > Beanshell or Groovy

  • Execute the following code in either Beanshell or Groovy to get your implementing class:

    de.hybris.platform.core.Registry.getApplicationContext().getBean("checkoutFacade");

Both consoles will show the result of the last expression in the Result tab.

In the Groovy console for Hybris 5.x, simple execute the following:

checkoutFacade

As you can see, each bean is automatically def-ed into each Groovy script.

As for Beanshell, you could create a bean function in Beanshell:

import de.hybris.platform.core.Registry;
import de.hybris.platform.commercefacades.order.CheckoutFacade;

Object bean(String beanName) 
{
    return Registry.getApplicationContext().getBean(beanName);
}

CheckoutFacade checkoutFacade = (CheckoutFacade) bean("checkoutFacade");
print(checkoutFacade);

I ended up using Beanshell so much that I created my own wrapper application that allows me to develop Beanshell in Eclipse, and use Eclipse as the Beanshell console. But that's a whole other post!

Resources:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top