2016-11-23 77 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