2016-11-23 78 views
2

我正在嘗試爲jira編寫一個事件監聽器插件。當我去舊的方式(其最新的SDK Atlassian的6.2.9一樣),並把這些2線春季掃描儀未檢測到組件

<component key="eventListener" class="jira.plugins.listeners.MyEventListener"/> 
<component-import key="eventPublisher" class="com.atlassian.event.api.EventPublisher"/> 

,並嘗試打包插件我得到一個警告說I cannot use component/component-import statement inside plugin descriptor file when Atlassian plugin key is set。最新的SDK使用Spring Scanner,它在骨​​架創建期間自動添加到pom.xml文件中,並強烈建議使用哪些文檔。所以我刪除從Atlassian的-plugin.xml文件的兩行,並嘗試與相應的註解來替代它們:

@Component 
public class MyEventListener{ 
    @Inject 
    public MyEventListener(@ComponentImport EventPublisher eventPublisher){ 
     eventPublisher.register(this); 
    } 

} 

我可以編譯和打包這種方式,但是當我在一個運行實例吉拉安裝它,在插件的說明中,它表示This plugin has no modules。我已經嘗試將@Component改爲@Named,將所有addind @ExportAsService都改爲無效。看來春季掃描儀不會將我的課程作爲一個組件進行檢測。有沒有人能夠解決這個問題?我已寫信給atlassian社區,但迄今尚未收到任何消息。

+0

我最近碰到這個也是,我還沒有想出如何讓模塊在列表中顯示出來,但我發現我的'@ EventListener's真的被稱爲反正。 您是否嘗試過在您的'@ EventListener'方法和/或構造函數中添加一些日誌記錄? –

+0

是的,我已經添加了日誌記錄,並且我沒有記錄任何內容。 –

回答

0

配置Spring掃描Maven插件在詳細模式下執行,並確保使用列入模式的構建過程中你的類進行處理。

<plugin> 
     <groupId>com.atlassian.plugin</groupId> 
     <artifactId>atlassian-spring-scanner-maven-plugin</artifactId> 
     <executions> 
      <execution> 
       <goals> 
        <goal>atlassian-spring-scanner</goal> 
       </goals> 
       <phase>process-classes</phase> 
      </execution> 
     </executions> 
     <configuration> 
      <includeExclude>+your.package.goes.here.*</includeExclude> 
      <verbose>true</verbose> 
     </configuration> 
    </plugin> 

如果一切正常,你的成分將在文件中列出構建目標/班/ META-INF /插件組件/組件

在個案後,@Component是在定義庫模塊(如託管插件的依賴),也可以使用配置元素

  <scannedDependencies> 
       <dependency> 
        <groupId>your.library.group.id</groupId> 
        <artifactId>your-library</artifactId> 
       </dependency> 
      </scannedDependencies> 

注意生成組件元數據:有是V1和V2春天掃描器之間的差異,請務必使用正確的版本。見reference