How to make a query inside a method of the Groovy class

In this case you need to do the same as in Java, stop using services (which is strictly a script oriented API), and @Inject the components you need.

Now it’s clear. Thanks tmortagne!.

I installed the extension and made an example as in the documentation.
https://extensions.xwiki.org/xwiki/bin/view/Extension/Script%20Component/
And it works:

But as soon as I add an inject it stops working:

As if something is missing. In the documentation, I see that the example has both an inject and an import. Maybe I missed something?

The current component code:

package org.xwiki.testcomponent.script;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

import org.xwiki.component.annotation.Component;
import org.xwiki.script.service.ScriptService;

@Component
@Named("testcomponent")
@Singleton
public class TestComponentScriptService implements ScriptService
{
 @Inject
 private QueryManager queryManager;
  
 public String get()
  {
    return "toto";
  }
}