4

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.

Henrique Ordine
  • 3,337
  • 4
  • 44
  • 70
  • Turn up the logging level. – bmargulies Jan 13 '14 at 11:53
  • org.springframework and stand back? – bmargulies Jan 13 '14 at 18:00
  • Another interesting thing you can do with Beanshell is selectively change the log levels at runtime. (Be careful on production - try this on dev machine first because it creates a very large log!) `org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.DEBUG);` It would be better to set the level on a specific logger instead of just the root, but that's just a simple example. – Aaron Blenkush Jan 14 '14 at 17:03

1 Answers1

6

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:

Community
  • 1
  • 1
Aaron Blenkush
  • 3,034
  • 2
  • 28
  • 54