Skip to Content

@autowired vs @resource? which is recommended way to inject beans in hybris?

Please answer this. Which is the recommended way by hybris? Elaborate the answer.

0
Add a comment
10|10000 characters needed characters exceeded

author's profile photo Former Member
Former Member Sep 01, 2014 at 10:04 AM

0

977

Actions

1 Answer

Best Answer
Wojciech Gruszczyk
Sep 01, 2014 at 10:38 AM
6

Hi,

it all depends on what you want to achieve. If you want to rely on beans' names (which is the prefered way at hybris) you should use @Resource annotation. @Autowire ootb wires by type.

In Spring @Resouce wires by name and if fails uses a fallback mechanism similar to @Autowire (wires by type). A good discussion on this topic can be found at http://stackoverflow.com/questions/4093504/resource-vs-autowired.

Cheers, Wojtek

Add a comment
10|10000 characters needed characters exceeded

  • Former Member Wojciech Gruszczyk

    Note that @Autowired is not supported for injection in ServicelayerIntegrationTest (or any JUnit test that starts the platform). It would not be too useful except with a @Qualifier annotation anyway. This is because spring is not doing the wiring, hybris framework is, and looks for @Resource annotation.