2017-05-07 33 views
2

我正在爲Jira構建一個插件。我想添加一個緩存層,所以我想使用com.atlassian.cache.CacheManager。我必須通過一個參數/ setter注入這個。Jira/Java - 注入管理器不工作(setter)

由於我在擴展其他課程,我希望通過一個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

回答

0

你的問題中提到JIRA,但您提供的文檔鏈接是合流(和過時的)。

如果您正在爲最新版本的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; 
    } 
}