Confluence NoSuchBeanDefinitionException com.atlassian.sal.api.*

I’ve been trying and failed for the past week to follow this guide to create a settings page for my basic plugin:
Creating an admin configuration form (atlassian.com)

However every dependency injection that is using the com.atlassian.sal:sal-api:4.4.0 failes with the error NoSuchBeanDefinitionException. I am able to inject classes from other packages just fine. These are are some that causes the error:

  • com.atlassian.sal.api.auth.LoginUriProvider
  • com.atlassian.sal.api.user.UserManager;
  • com.atlassian.sal.api.pluginsettings.PluginSettingsFactory;
  • com.atlassian.sal.api.transaction.TransactionTemplate;
  • com.atlassian.templaterenderer.TemplateRenderer (Not SAL but same error);

Been trying different solutions that I’ve found but neither works.

  • Tried using ContainerManager to import by name. Same error.
  • Tried to use different annotations for class and property @Named, @Scanned (not found), @Inject, @ConfluenceImport, @ComponentImport @ComponentImport(“pluginSettingsFactory”) etc.
  • Updated confluence version in pom to 7.18.1
  • Other random tests I can’t remember right now.

I’ve found ConfluencePluginSettingsFactory (Atlassian Confluence 7.18.1 API) and thought maybe I need to use Confluenc specific factory but that class cannot be found and I am not able to find ANY usages so not sure how that’s implemented.

Can someone for the love of anything please give me any hints on how to continue? Thank you.

Code (at the moment):


import com.atlassian.sal.api.pluginsettings.PluginSettingsFactory;

@Path("/")
public class ConfigResource {

    @ComponentImport
    private final PluginSettingsFactory pluginSettingsFactory;

    @Inject
    public ConfigResource(PluginSettingsFactory pluginSettingsFactory) {
        this.pluginSettingsFactory = pluginSettingsFactory;
    }
...

Ok so the documentation around this seems off but this got it to work for me:

  1. Ignore this page which says it’s deprecated:
    Component Import module (atlassian.com)

  2. Follow this:
    UnsatisfiedDependencyException - error creating bean with name (atlassian.com)
    Where it says to import component in atlassian-pugin.xml

<atlassian-plugin ... >
    ...
    <component-import key="userManager" interface="com.atlassian.sal.api.user.UserManager"/>
    <component-import key="contentPropertyService" interface="com.atlassian.confluence.api.service.content.ContentPropertyService"/>
    <component-import key="loginUriProvider" interface="com.atlassian.sal.api.auth.LoginUriProvider"/>
    <component-import key="templateRenderer" interface="com.atlassian.templaterenderer.TemplateRenderer"/>
  1. Comment out or remove below from the pom.xml file:
<instructions>
    <Atlassian-Plugin-Key>${atlassian.plugin.key}</Atlassian-Plugin-Key>

    <!-- Add package to export here -->
    <Export-Package>
        se.ltu.confluence.plugin.api,
    </Export-Package>

    <!-- Add package import here -->
    <Import-Package>
         org.springframework.osgi.*;resolution:="optional",
         org.eclipse.gemini.blueprint.*;resolution:="optional",
         com.atlassian.sal.api.*;resolution:="optional",
        *
    </Import-Package>

    <!-- Ensure plugin is spring powered -->
    <Spring-Context>*</Spring-Context>
</instructions>