I’m building a plugin for Jira. I want to add a caching-layer so I wanted to use the
com.atlassian.cache.CacheManager
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;
}
@Override
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
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.
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: