OsgiPlugin - Plugin never resolved service error
That happens when you try to inject on an object of your plugin another object of your plugin and you do it as if the another object was of another different plugin and was exported as a public OSGi service.
In JIRA, you can declare your plugin Java classes as components. That means that the instantiation and dependency injection (through constructor for example) will be automatically delegated on the Spring Framework which is part of JIRA. Usually we do this to lose care about instantiation and class dependencies. There are two types of components, public and private. Public components will be available to import for different plugins than yours. Other plugins can import them and then use them through dependency injection. Private components will work the same as public ones but other plugins will not be able to import or see them.
If you have one component, say A
, which depends on another component, B
, both of them part of your plugin, you should not import component B
to be available for A
because it is already part of your plugin. Before JIRA 7 for importing a component you placed on the atlassian-plugin.xml
a <component-import>
element. JIRA 7 onwards you put @ComponentImport
before the constructor parameter when you do dependency injection through constructor.
So I think what you did wrong was to put <component-import>
on a component that comes directly from your plugin instead of having <component>
. Or if you have JIRA 7 or later version what you did wrong was to put @ComponentImport
before a component of your own plugin and the solution there would be to remove that annotation. At least this last one was my case and removing that annotations from dependency injection of components coming from the same plugin I made it to work.
Had a similar problem like this when I was developing a plugin for Confluence v6.1.3. I was migrating from Atlassian Spring Scanner v1 to v2. After following the instructions in the Atlassian Spring Scanner v2 guide, I thought it was good to go but had this error:
[INFO] [talledLocalContainer] 2017-08-24 22:54:52,602 ERROR [localhost-startStop-1] [plugin.osgi.factory.OsgiPlugin] logAndClearOustandingDependencies Plugin 'com.confluenceservice.confluence.plugin.page-viewed' never resolved service '&pageViewedService' with filter '(&(objectClass=com.confluenceservice.confluence.plugin.PageViewedService)(objectClass=com.confluenceservice.confluence.plugin.PageViewedService))'
The cause of this error was the @ComponentImport PageViewedService service
:
@Autowired
public AlertUserMacro(@ComponentImport PageViewedService service,
@ComponentImport PageManager pageManager) {
//constructor...
}
This was ok in Spring Scanner v1 but not in Spring Scanner v2. The import isn't needed because PageViewedService
is part of my plugin. I needed to import PageManager
because its scope is outside of my plugin. The solution:
@Autowired
public AlertUserMacro(PageViewedService service, @ComponentImport PageManager pageManager) {
//constructor
}
Hope this helps.