Component injection failed

Hello,

I’m currently trying to user other components in a custom component i’ve made. I follow the example but the component i try to import is always null.

I put above the code :

@Component
public class GetPagesService {

    @Inject
    private QueryManager queryManager;

    public String getVisiblesPages() {
          Class test = queryManager.getClass();
    }
}

In this example queryManager is always null and i dont know what i miss. To add some precisions, i deploy my component manually.

Greetings

Hi,

Could you show us your components.txt? (see https://extensions.xwiki.org/xwiki/bin/view/Extension/Component%20Module#HComponentRegistration)

Thx

BTW you’re also missing the lifecycle annotation. If you use xwiki’s maven build you should get errors about all these automatically.

Also you’re missing a role interface…

In short you need to follow https://extensions.xwiki.org/xwiki/bin/view/Extension/Component%20Module :slight_smile:

This means GetPagesService is not a component. The @Component annotation is not enough to make all instances of this class components, it needs to be initialized as a component either by being injected in another component or by using ComponentManager#getInstance API (i.e. you cannot use new to create a component).