cq5 - What is difference between @Reference & getScriptHelper() in CQ? -


i looking cq code , found services can obtained using either

@reference  private jcrservice searchservice; 

or

taxonomyservice taxonomyservice = getscripthelper()             .getservice(taxonomyservice.class); 

what difference betwen 2 approaches , 1 better?

the scripthelper meant give access osgi services presentation layer (jsp, sightly, etc), if in component, @reference best way reference service.

it has several advantages, since injected service component runtime (scr). example:

  • define if reference static or dynamic
  • you can component wont activate if dependencies not available
  • define cardinality of reference
  • use filter specific target , specific instance, example.

Comments