【问题标题】:Jira/Java - injecting manager not working (setter)Jira/Java - 注入管理器不起作用(setter)
【发布时间】:2017-05-17 17:07:22
【问题描述】:

我正在为 Jira 构建一个插件。我想添加一个缓存层,所以我想使用com.atlassian.cache.CacheManager。我必须通过参数/设置器注入它。

由于我正在扩展另一个类,因此我想通过 setter 注入它,但由于某种原因,它始终返回 null

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");

    }
}

我还尝试了以下操作:

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

之后插件不再执行任何操作。我没有收到错误,但它只给出 0 输出。

我将它用于文档:https://developer.atlassian.com/confdev/confluence-plugin-guide/writing-confluence-plugins/accessing-confluence-components-from-plugin-modules

还有https://developer.atlassian.com/confdev/development-resources/confluence-developer-faq/how-do-i-cache-data-in-a-plugin#HowdoIcachedatainaplugin?-Instructions

【问题讨论】:

    标签: java jira


    【解决方案1】:

    您的问题提到了 JIRA,但您提供的文档链接适用于 Confluence(并且已过时)。

    如果您正在为最新版本的 JIRA (7.2+) 开发插件,那么注入组件现在由 Atlassian Spring Scanner 2 处理,因此一切都可以使用注释。

    如果您按照here 列出的说明进行操作,那么您应该能够通过构造函数注入组件,如下所示:

    @Component
    public class MyService {
        private final IssueService issueService;
        private final InternalComponent internalComponent;
    
        @Inject
        public MyService(@ComponentImport final IssueService issueService,final InternalComponent internalComponent) {
            this.issueService = issueService;
            this.internalComponent = internalComponent;
        } 
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-24
      • 1970-01-01
      • 2013-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多