cancel
Showing results for 
Search instead for 
Did you mean: 

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

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

former_member632755
Active Contributor

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

Former Member
0 Kudos

Thank you for quick response. I have recently read this documentation. https://wiki.hybris.com/display/release4/Overview+of+Changes+to+the+hybris+Multichannel+Accelerator+...

Here they mentioned that , @autowired has replaced by @resource annotation. Is this hybris recommended way?

former_member632755
Active Contributor
0 Kudos

For short - yes, @Resource should be considered as the recommended annotation. Nevertheless @Autowired is also supported and if you are using it by purpose it's totally fine i.e. you should NOT consider @Autowired as depreceted.

Former Member
0 Kudos

okay. Thanks. The link you shared is really informative. Based on documentation , i will use @resource.

Former Member
0 Kudos

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.

Answers (0)