How to access a component created through the Script Component extension from another component

Hi!
I created the component using the extension as described here:https://extensions.xwiki.org/xwiki/bin/view/Extension/Script%20Component/

How do I access it in another component of the same type?
For example, if my component has the name “test1”

in it and I want to use its method in another component named “test2”

It’s just that the inject doesn’t work as written.

Do I need to announce more imports? But what is the namespace?

That’s because test1 is not a component role type. You might want to take a look at https://extensions.xwiki.org/xwiki/bin/view/Extension/Component%20Module to understand a bit better how components works.

If you were looking at the log of your application server, you would notice an error telling you that test1 is not a class so it does not make sense to use that here, something like:

Script4.groovy: 16: unable to resolve class test1

To summarize, a component has a role type and a role hint. In the case of your test1ScriptService component the role type is org.xwiki.script.service.ScriptService and the role hint is "test1".

So the injection for this specific component should look more like:

@Inject
@Named("test1")
private ScriptService test1
1 Like

It’s working. Thank you very much.