Injecting cacheManager not working (setter)

I’m building a plugin for Jira. I want to add a caching-layer so I wanted to use the

I have to inject this via an argument / setter.

Since I’m extending an other class I wanted to inject this via a setter, but for some reason it returns null all the time. It does not go past the setter.

import com.atlassian.cache.Cache;
import com.atlassian.cache.CacheLoader;
import com.atlassian.cache.CacheManager;
import com.atlassian.cache.CacheSettingsBuilder;

public class Foo extends AbstractJiraContextProvider
    private CacheManager cacheManager;

    public void setCacheManager(CacheManager cacheManager) {
        //It does not get past this function..
        this.cacheManager = cacheManager;

    public Map getContextMap(ApplicationUser user, JiraHelper jiraHelper) {

        cache = this.cacheManager.getCache("bar");


I also tried this by doing the following:

public Foo(CacheManager cacheManager) {
    this.cacheManager = cacheManager;

After that the plugin does nothing anymore. I do not get errors, but it just gives 0 output nor logs

I used this for documentation:


Constructor injection is the right way for that. You aren’t using it for anything so there will be no output. If you debug your addon after deployment, you’ll be able to break on the constructor and confirm its been injected. Assuming you have declared Foo as a Component in your atlassian-plugin.xml you’ll be able to inject it into any simple REST service or Webwork action to drive the component to be provided and hook your debugger.

Regarding your links, they are for confluence. This post is for JIRA Development. JIRA uses constructor injection.


Remember, you’ll need to component-import the CacheManager in your atlassian-plugin.xml file.

<component-import key="cacheManager"
                  interface="com.atlassian.cache.CacheManager" />

Well it gives the following error when I do that:

atlassian-plugin.xml contains a definition of component-import. This is not allowed when Atlassian-Plugin-Key is set.

I now believe the latest and greatest is to use the @ComponentImport annotation, as described in this StackOverflow post.

Ye, the only issue is that I get this error on using @ComponentImport

[ERROR] cannot find symbol: class ComponentImport

If you’ve got Atlassian-Plugin-Key in the pom.xml - then you’re using the new style Component importing using @ComponentImport. The one thing to note is that you may have to declare the class to be imported in the pom.xml:


You will also need to make sure you have the right annotations in the dependencies:

1 Like