如何在Atlassian SDK中使用带有注释的Active Objects [英] How to use Active Objects with annotation in atlassian sdk

查看:75
本文介绍了如何在Atlassian SDK中使用带有注释的Active Objects的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了Jira插件,我需要使用Active Object. (吉拉v7.1.8) 但是在官方文档中已经过时了.它是使用xml编写的,但是如果我理解正确,现在可以使用Atlassian Spring Scanner(我使用v1.2.3)

I do Jira plugin and I need to use Active Object. (Jira v7.1.8) But in official documentation is outdated. It is written using xml, but if I understood correctly, now used Atlassian Spring Scanner (I use v1.2.3)

遵循此手册 https://bitbucket.org/atlassian/atlassian-spring-scanner/src/1.2.x/README.md?at=1.2.x&fileviewer=file-view-default 没有成功.

atlassian-plugin.xml

    <atlassian-plugin key="${project.groupId}.${project.artifactId}" name="${project.name}" plugins-version="2">
    <plugin-info>
        <description>${project.description}</description>
        <version>${project.version}</version>
        <vendor name="${project.organization.name}" url="${project.organization.url}" />
        <param name="plugin-icon">images/pluginIcon.png</param>
        <param name="plugin-logo">images/pluginLogo.png</param>
    </plugin-info>

    <!-- add our i18n resource -->
    <resource type="i18n" name="i18n" location="dbplugin"/>

    <web-resource key="my-resources">
        <dependency>com.atlassian.jira.jira-project-config-plugin:project-config-global</dependency>
        <context>my-resources</context>
    </web-resource>
    <!----------- This is old xml version ------------------
        <component-import key="ao" name="Active Objects service" interface="com.atlassian.activeobjects.external.ActiveObjects">
            <description>Component to access Active Objects functionality from the plugin</description>
        </component-import>

 <component key="dao-factory" class="com.lemon.dbplugin.DAO.DAOFactory">
            </component>
    -------------------------------------------------------->
        <ao key="ao-module">
            <entity>com.lemon.dbplugin.entity.StudentEntity</entity>
        </ao>



    <webwork1 key="actions" name="MyActions">
        <actions>
            <action name="com.lemon.dbplugin.ActionAlpha" alias="action" roles-required="admin">
                <view name="success">/templates/success.vm</view>
            </action>
        </actions>
    </webwork1>

ActionAlpha

package com.lemon.dbplugin;


import com.atlassian.jira.project.Project;
import com.atlassian.jira.web.action.JiraWebActionSupport;
import com.lemon.dbplugin.DAO.DAOFactory;
import com.lemon.dbplugin.entity.StudentEntity;
import com.lemon.dbplugin.logic.Student;
import com.lemon.dbplugin.logic.StudentImpl;
import org.apache.log4j.Logger;
import webwork.action.ServletActionContext;

public class ActionAlpha extends JiraWebActionSupport {

private static final Logger log = Logger.getLogger(ActionAlpha.class);
private Project project;
private StudentEntity[] students;

@Override
public String execute() throws Exception {
    log.debug("Entered in execute ActionAlpha");
    project = getSelectedProjectObject();
    getHttpRequest().setAttribute("com.atlassian.jira.projectconfig.util.ServletRequestProjectConfigRequestCache:project", project);
    students = DAOFactory.getInstance().getStudentDAO().getStudents();
    log.debug("students :" + students);
    return super.execute();
}
public String doAdd() throws Exception {
    log.debug("Entered in doAdd ActionAlpha");
    String name = getHttpRequest().getParameterValues("name")[0];
    Student student = new StudentImpl(name);
    log.debug("student :" + student);
    DAOFactory.getInstance().getStudentDAO().addStudent(student);
    ServletActionContext.getResponse().sendRedirect("/secure/action.jspa");
    return NONE;
}

}

DAOFactory

package com.lemon.dbplugin.DAO;


import com.atlassian.activeobjects.external.ActiveObjects;
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
import com.lemon.dbplugin.DAO.Impl.StudentDAOImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@Component
public class DAOFactory {
    private static StudentDAO studentDAO = null;
    private static DAOFactory instance = null;
@ComponentImport private static ActiveObjects ao;

@Autowired
public DAOFactory(@ComponentImport ActiveObjects ao) {
    DAOFactory.ao = ao;
}
public static synchronized DAOFactory getInstance() {
    if (instance == null) {
        instance = new DAOFactory(ao);
    }
    return instance;
}
public StudentDAO getStudentDAO() {
    if (studentDAO == null) {
        studentDAO = new StudentDAOImpl(ao);
    }
    return studentDAO;
}

}

StudentDAOImpl

package com.lemon.dbplugin.DAO.Impl;

import com.atlassian.activeobjects.external.ActiveObjects;
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
import com.atlassian.sal.api.transaction.TransactionCallback;
import com.lemon.dbplugin.DAO.StudentDAO;
import com.lemon.dbplugin.entity.StudentEntity;
import com.lemon.dbplugin.logic.Student;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;


public class StudentDAOImpl implements StudentDAO {


    private final ActiveObjects ao;
    private static final Logger log = Logger.getLogger(StudentDAOImpl.class);


    @Autowired
    public StudentDAOImpl(@ComponentImport ActiveObjects ao) {
        this.ao = ao;
    }

    @Override
    public StudentEntity addStudent(final Student student) throws Exception {
        log.debug("Entered to addStudents");
        log.debug("AO :" + ao);
        return ao.executeInTransaction(new TransactionCallback<StudentEntity>() {
            public StudentEntity doInTransaction() {
                StudentEntity entity = ao.create(StudentEntity.class);
                entity.setName(student.getName());
                entity.setCreated(new Date(System.currentTimeMillis()));
                entity.save();
                return entity;
            }
        });
    }

    public StudentEntity[] getStudents() throws Exception {
        log.debug("Entered to getStudents");
        log.debug("ao: " + ao);

        try {
            return ao.executeInTransaction(new TransactionCallback<StudentEntity[]>() {
                public StudentEntity[] doInTransaction() {
                    StudentEntity[] result = ao.find(StudentEntity.class);
                    if (result != null) {
                        return ao.find(StudentEntity.class);
                    } else {
                        return new StudentEntity[]{};
                    }
                }
            });
        }
        catch(NullPointerException e){
            return new StudentEntity[]{};
        }
    }
}

编译并打包所有错误.但是,如果我尝试打开/jira/secure/action.jspa, 在控制台中,我得到以下信息:

Compile and package whithout errors. But if I try open /jira/secure/action.jspa, in console I get this:

[INFO] [talledLocalContainer] 2016-06-30 09:38:15,837 http-nio-2990-exec-8 DEBUG admin 578x129x1 bnt30i 10.0.0.120 /rest/plugins/1.0/com.lemon.dbplugin.dbplugin-key [c.a.activeobjects.osgi.OsgiServiceUtilsImpl] Registering service net.java.ao.atlassian.AtlassianTableNameConverter@16856656 with interface net.java.ao.schema.TableNameConverter and properties {com.atlassian.plugin.key=com.lemon.dbplugin.dbplugin}
[INFO] [talledLocalContainer] 2016-06-30 09:38:15,839 http-nio-2990-exec-8 DEBUG admin 578x129x1 bnt30i 10.0.0.120 /rest/plugins/1.0/com.lemon.dbplugin.dbplugin-key [c.a.activeobjects.osgi.OsgiServiceUtilsImpl] Registering service com.atlassian.activeobjects.config.internal.DefaultActiveObjectsConfiguration@3cf99a08 with interface com.atlassian.activeobjects.config.ActiveObjectsConfiguration and properties {com.atlassian.plugin.key=com.lemon.dbplugin.dbplugin}
[INFO] [talledLocalContainer] 2016-06-30 09:38:15,845 http-nio-2990-exec-8 DEBUG admin 578x129x1 bnt30i 10.0.0.120 /rest/plugins/1.0/com.lemon.dbplugin.dbplugin-key [c.a.activeobjects.osgi.ActiveObjectsServiceFactory] onPluginModuleEnabledEvent storing unattached <ao> configuration module for [com.lemon.dbplugin.dbplugin]
[INFO] [talledLocalContainer] 2016-06-30 09:38:15,875 http-nio-2990-exec-8 DEBUG admin 578x129x1 bnt30i 10.0.0.120 /rest/plugins/1.0/com.lemon.dbplugin.dbplugin-key [c.a.activeobjects.osgi.ActiveObjectsServiceFactory] onPluginEnabledEvent attaching unbound <ao> to [com.lemon.dbplugin.dbplugin]
[INFO] [talledLocalContainer] 2016-06-30 09:38:15,876 http-nio-2990-exec-8 DEBUG admin 578x129x1 bnt30i 10.0.0.120 /rest/plugins/1.0/com.lemon.dbplugin.dbplugin-key [c.a.activeobjects.osgi.TenantAwareActiveObjects] init bundle [com.lemon.dbplugin.dbplugin]
[INFO] [talledLocalContainer] 2016-06-30 09:38:15,876 http-nio-2990-exec-8 DEBUG admin 578x129x1 bnt30i 10.0.0.120 /rest/plugins/1.0/com.lemon.dbplugin.dbplugin-key [c.a.activeobjects.osgi.TenantAwareActiveObjects] bundle [com.lemon.dbplugin.dbplugin] loading new AO promise for JiraTenantImpl{id='system'}
[INFO] [talledLocalContainer] 2016-06-30 09:38:15,876 http-nio-2990-exec-8 DEBUG admin 578x129x1 bnt30i 10.0.0.120 /rest/plugins/1.0/com.lemon.dbplugin.dbplugin-key [c.a.activeobjects.osgi.TenantAwareActiveObjects] setAoConfiguration [com.lemon.dbplugin.dbplugin]
[INFO] [talledLocalContainer] 2016-06-30 09:38:15,876 http-nio-2990-exec-8 DEBUG admin 578x129x1 bnt30i 10.0.0.120 /rest/plugins/1.0/com.lemon.dbplugin.dbplugin-key [c.a.activeobjects.osgi.TenantAwareActiveObjects] bundle [com.lemon.dbplugin.dbplugin] got ActiveObjectsConfiguration
[INFO] [talledLocalContainer] 2016-06-30 09:38:15,877 active-objects-init-JiraTenantImpl{id='system'}-0 DEBUG admin     [c.a.activeobjects.osgi.TenantAwareActiveObjects] bundle [com.lemon.dbplugin.dbplugin] creating ActiveObjects
[INFO] [talledLocalContainer] 2016-06-30 09:38:15,905 active-objects-init-JiraTenantImpl{id='system'}-0 DEBUG admin     [c.a.activeobjects.osgi.TenantAwareActiveObjects] bundle [com.lemon.dbplugin.dbplugin] created ActiveObjects
[INFO] [talledLocalContainer] 2016-06-30 09:38:53,798 http-nio-2990-exec-12 ERROR admin 578x184x1 bnt30i 10.0.0.120 /secure/action.jspa [c.a.j.config.webwork.JiraActionFactory] Error autowiring Action 'com.lemon.dbplugin.ActionAlpha'.
[INFO] [talledLocalContainer] java.lang.NullPointerException
[INFO] [talledLocalContainer]   at com.atlassian.jira.config.webwork.JiraActionFactory$JiraPluginActionFactory.getActionImpl(JiraActionFactory.java:389)
[INFO] [talledLocalContainer]   at webwork.action.factory.PrefixActionFactoryProxy.getActionImpl(PrefixActionFactoryProxy.java:99)
[INFO] [talledLocalContainer]   at webwork.action.factory.JspActionFactoryProxy.getActionImpl(JspActionFactoryProxy.java:59)
[INFO] [talledLocalContainer]   at webwork.action.factory.CommandActionFactoryProxy.getActionImpl(CommandActionFactoryProxy.java:60)
[INFO] [talledLocalContainer]   at com.atlassian.jira.config.webwork.LookupAliasActionFactoryProxy.getActionImpl(LookupAliasActionFactoryProxy.java:61)
[INFO] [talledLocalContainer]   at webwork.action.factory.CommandActionFactoryProxy.getActionImpl(CommandActionFactoryProxy.java:60)
[INFO] [talledLocalContainer]   at webwork.action.factory.ContextActionFactoryProxy.getActionImpl(ContextActionFactoryProxy.java:36)
[INFO] [talledLocalContainer]   at webwork.action.factory.PrepareActionFactoryProxy.getActionImpl(PrepareActionFactoryProxy.java:37)
[INFO] [talledLocalContainer]   at com.atlassian.jira.config.webwork.JiraActionFactory$SafeParameterSettingActionFactoryProxy.getActionImpl(JiraActionFactory.java:147)
[INFO] [talledLocalContainer]   at webwork.action.factory.ChainingActionFactoryProxy.getActionImpl(ChainingActionFactoryProxy.java:53)
[INFO] [talledLocalContainer]   at com.atlassian.jira.config.webwork.JiraActionFactory.getActionImpl(JiraActionFactory.java:301)
[INFO] [talledLocalContainer]   ... 2 filtered
[INFO] [talledLocalContainer]   at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
[INFO] [talledLocalContainer]   ... 55 filtered
[INFO] [talledLocalContainer]   at com.atlassian.greenhopper.jira.filters.ClassicBoardRouter.doFilter(ClassicBoardRouter.java:59)
[INFO] [talledLocalContainer]   ... 27 filtered
[INFO] [talledLocalContainer]   at com.atlassian.labs.httpservice.resource.ResourceFilter.doFilter(ResourceFilter.java:59)
[INFO] [talledLocalContainer]   ... 38 filtered
[INFO] [talledLocalContainer]   at com.atlassian.jira.security.JiraSecurityFilter.doFilter(JiraSecurityFilter.java:70)
[INFO] [talledLocalContainer]   ... 38 filtered
[INFO] [talledLocalContainer]   at com.atlassian.servicedesk.internal.web.CustomerContextSettingFilter.lambda$invokeFilterChain$0(CustomerContextSettingFilter.java:169)
[INFO] [talledLocalContainer]   at com.atlassian.servicedesk.internal.util.scala.ScalaJavaInterOp$1.apply(ScalaJavaInterOp.java:25)
[INFO] [talledLocalContainer]   at com.atlassian.servicedesk.internal.utils.context.CustomerContextUtil$.outOfCustomerContext(CustomerContextUtil.scala:48)
[INFO] [talledLocalContainer]   at com.atlassian.servicedesk.internal.utils.context.CustomerContextUtil.outOfCustomerContext(CustomerContextUtil.scala)
[INFO] [talledLocalContainer]   at com.atlassian.servicedesk.internal.utils.context.CustomerContextServiceImpl.outOfCustomerContext(CustomerContextServiceImpl.java:24)
[INFO] [talledLocalContainer]   at com.atlassian.servicedesk.internal.web.CustomerContextSettingFilter.outOfCustomerContext(CustomerContextSettingFilter.java:164)
[INFO] [talledLocalContainer]   at com.atlassian.servicedesk.internal.web.CustomerContextSettingFilter.doFilterImpl(CustomerContextSettingFilter.java:120)
[INFO] [talledLocalContainer]   at com.atlassian.servicedesk.internal.web.CustomerContextSettingFilter.doFilter(CustomerContextSettingFilter.java:112)
[INFO] [talledLocalContainer]   ... 55 filtered
[INFO] [talledLocalContainer]   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
[INFO] [talledLocalContainer]   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
[INFO] [talledLocalContainer]   at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
[INFO] [talledLocalContainer]   at java.lang.Thread.run(Thread.java:745)
[INFO] [talledLocalContainer] 2016-06-30 09:38:53,801 http-nio-2990-exec-12 ERROR admin 578x184x1 bnt30i 10.0.0.120 /secure/action.jspa [c.a.j.web.dispatcher.JiraWebworkActionDispatcher] Exception thrown from action 'action', returning 404
[INFO] [talledLocalContainer] java.lang.NullPointerException
[INFO] [talledLocalContainer]   at com.atlassian.jira.config.webwork.JiraActionFactory$JiraPluginActionFactory.getActionImpl(JiraActionFactory.java:389)
[INFO] [talledLocalContainer]   at webwork.action.factory.PrefixActionFactoryProxy.getActionImpl(PrefixActionFactoryProxy.java:99)
[INFO] [talledLocalContainer]   at webwork.action.factory.JspActionFactoryProxy.getActionImpl(JspActionFactoryProxy.java:59)
[INFO] [talledLocalContainer]   at webwork.action.factory.CommandActionFactoryProxy.getActionImpl(CommandActionFactoryProxy.java:60)
[INFO] [talledLocalContainer]   at com.atlassian.jira.config.webwork.LookupAliasActionFactoryProxy.getActionImpl(LookupAliasActionFactoryProxy.java:61)
[INFO] [talledLocalContainer]   at webwork.action.factory.CommandActionFactoryProxy.getActionImpl(CommandActionFactoryProxy.java:60)
[INFO] [talledLocalContainer]   at webwork.action.factory.ContextActionFactoryProxy.getActionImpl(ContextActionFactoryProxy.java:36)
[INFO] [talledLocalContainer]   at webwork.action.factory.PrepareActionFactoryProxy.getActionImpl(PrepareActionFactoryProxy.java:37)
[INFO] [talledLocalContainer]   at com.atlassian.jira.config.webwork.JiraActionFactory$SafeParameterSettingActionFactoryProxy.getActionImpl(JiraActionFactory.java:147)
[INFO] [talledLocalContainer]   at webwork.action.factory.ChainingActionFactoryProxy.getActionImpl(ChainingActionFactoryProxy.java:53)
[INFO] [talledLocalContainer]   at com.atlassian.jira.config.webwork.JiraActionFactory.getActionImpl(JiraActionFactory.java:301)
[INFO] [talledLocalContainer]   ... 2 filtered
[INFO] [talledLocalContainer]   at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
[INFO] [talledLocalContainer]   ... 55 filtered
[INFO] [talledLocalContainer]   at com.atlassian.greenhopper.jira.filters.ClassicBoardRouter.doFilter(ClassicBoardRouter.java:59)
[INFO] [talledLocalContainer]   ... 27 filtered
[INFO] [talledLocalContainer]   at com.atlassian.labs.httpservice.resource.ResourceFilter.doFilter(ResourceFilter.java:59)
[INFO] [talledLocalContainer]   ... 38 filtered
[INFO] [talledLocalContainer]   at com.atlassian.jira.security.JiraSecurityFilter.doFilter(JiraSecurityFilter.java:70)
[INFO] [talledLocalContainer]   ... 38 filtered
[INFO] [talledLocalContainer]   at com.atlassian.servicedesk.internal.web.CustomerContextSettingFilter.lambda$invokeFilterChain$0(CustomerContextSettingFilter.java:169)
[INFO] [talledLocalContainer]   at com.atlassian.servicedesk.internal.util.scala.ScalaJavaInterOp$1.apply(ScalaJavaInterOp.java:25)
[INFO] [talledLocalContainer]   at com.atlassian.servicedesk.internal.utils.context.CustomerContextUtil$.outOfCustomerContext(CustomerContextUtil.scala:48)
[INFO] [talledLocalContainer]   at com.atlassian.servicedesk.internal.utils.context.CustomerContextUtil.outOfCustomerContext(CustomerContextUtil.scala)
[INFO] [talledLocalContainer]   at com.atlassian.servicedesk.internal.utils.context.CustomerContextServiceImpl.outOfCustomerContext(CustomerContextServiceImpl.java:24)
[INFO] [talledLocalContainer]   at com.atlassian.servicedesk.internal.web.CustomerContextSettingFilter.outOfCustomerContext(CustomerContextSettingFilter.java:164)
[INFO] [talledLocalContainer]   at com.atlassian.servicedesk.internal.web.CustomerContextSettingFilter.doFilterImpl(CustomerContextSettingFilter.java:120)
[INFO] [talledLocalContainer]   at com.atlassian.servicedesk.internal.web.CustomerContextSettingFilter.doFilter(CustomerContextSettingFilter.java:112)
[INFO] [talledLocalContainer]   ... 55 filtered
[INFO] [talledLocalContainer]   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
[INFO] [talledLocalContainer]   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
[INFO] [talledLocalContainer]   at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
[INFO] [talledLocalContainer]   at java.lang.Thread.run(Thread.java:745)

抱歉这个愚蠢的问题,我在做什么错了?

Sorry for the stupid question, what am I doing wrong?

推荐答案

经过数周的网上搜索和大量尝试的错误,我终于获得了官方的Active Objects教程,可与最新版本的Jira(7.1.2)一起使用. )和spring-scanner 2.0支持.

After weeks of searching the web and lot's of trial an error, I finally got the official Active Objects tutorial to work with the latest version of Jira (7.1.2) and spring-scanner 2.0 support.

您可以在 GitHub 上找到完整的代码示例,但这是本文的要旨.它:

You can find the full code sample on GitHub, but here is the gist of it:

正确声明您的付款方式

 <!-- Active Objects -->
    <dependency>
        <groupId>com.atlassian.activeobjects</groupId>
        <artifactId>activeobjects-plugin</artifactId>
        <version>${ao.version}</version>
        <scope>provided</scope>
    </dependency>
    <!-- SAL, the Active Objects plugin uses SAL's API for transactions -->
    <dependency>
        <groupId>com.atlassian.sal</groupId>
        <artifactId>sal-api</artifactId>
        <version>${sal.version}</version>
        <scope>provided</scope>
    </dependency>
    <!-- Dependency Injection -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring.version}</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.atlassian.plugin</groupId>
        <artifactId>atlassian-spring-scanner-annotation</artifactId>
        <version>${atlassian.spring.scanner.version}</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>${slf4j.version}</version>
        <scope>compile</scope>
    </dependency>

配置弹簧扫描器

<build>
    <plugins>
        <plugin>
            <groupId>com.atlassian.maven.plugins</groupId>
            <artifactId>maven-jira-plugin</artifactId>
            <version>${amps.version}</version>
            <extensions>true</extensions>
            <configuration>
                <productVersion>${jira.version}</productVersion>
                <productDataVersion>${jira.version}</productDataVersion>
                <enableQuickReload>true</enableQuickReload>
                <enableFastdev>false</enableFastdev>
                <instructions>
                    <Atlassian-Plugin-Key>${atlassian.plugin.key}</Atlassian-Plugin-Key>
                    <!-- Add package to export here -->
                    <Export-Package>com.atlassian.tutorial.ao.todo.api,</Export-Package>
                    <!-- Add package import here -->
                    <Import-Package>
                        org.springframework.osgi.*;resolution:="optional",
                        org.eclipse.gemini.blueprint.*;resolution:="optional",
                        *
                    </Import-Package>
                    <!-- Ensure plugin is spring powered -->
                    <Spring-Context>*</Spring-Context>
                </instructions>
            </configuration>
        </plugin>

        <plugin>
            <groupId>com.atlassian.plugin</groupId>
            <artifactId>atlassian-spring-scanner-maven-plugin</artifactId>
            <version>${atlassian.spring.scanner.version}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>atlassian-spring-scanner</goal>
                    </goals>
                    <phase>process-classes</phase>
                </execution>
            </executions>
            <configuration>
                <verbose>false</verbose>
            </configuration>
        </plugin>
    </plugins>
</build>

属性

<properties>
    <!--
    This key is used to keep the consistency between the key in atlassian-plugin.xml
    and the key to generate bundle.
    -->
    <atlassian.plugin.key>${project.groupId}.${project.artifactId}</atlassian.plugin.key>
    <jira.version>7.2.1</jira.version>
    <!--
    For correct versions to use with your Atlassian product see target folder, i.e.
    /target/container/tomcat8x/cargo-jira-home/webapps/jira/WEB-INF/lib
    -->
    <amps.version>6.2.4</amps.version>
    <ao.version>1.0.0</ao.version>
    <sal.version>2.6.0</sal.version>
    <slf4j.version>1.7.9</slf4j.version>
    <testkit.version>6.3.11</testkit.version>
    <plugin.testrunner.version>1.2.3</plugin.testrunner.version>
    <spring.version>4.1.6.RELEASE</spring.version>
    <!-- See https://bitbucket.org/atlassian/atlassian-spring-scanner -->
    <atlassian.spring.scanner.version>1.2.6</atlassian.spring.scanner.version>
    <!--Determined by JEE compliant container-->
    <servlet.version>3.1.0</servlet.version>
</properties>

** Spring Context ** 您还需要使用/resources/META-INF/spring/plugin-context.xml

** Spring Context** You also need to configure spring with an /resources/META-INF/spring/plugin-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:atlassian-scanner="http://www.atlassian.com/schema/atlassian-scanner/2"
xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.atlassian.com/schema/atlassian-scanner/2
    http://www.atlassian.com/schema/atlassian-scanner/2/atlassian-scanner.xsd">
<atlassian-scanner:scan-indexes autowire="constructor" />
</beans>

Java Beans

然后,您可以使用@Component标记Java类以进行依赖项注入.

Then you can use @Component to mark your java class for dependency injection.

由于我们将autowire="constructor"放入了plugin-context.xml中,因此不再需要@Autowired@Inject注释来进行构造函数注入.

Since we put autowire="constructor" in our plugin-context.xml, we don't need @Autowired or @Inject annotations for constructor injection anymore.

您自己的bean将自动注入,外部bean必须使用@ComponentImport投放市场:

Your own beans will be injected automatically, external beans have to be market with @ComponentImport:

@Component
public final class TodoServlet extends HttpServlet {
   private final TodoService todoService;
   private final UserManager userManager;

    public TodoServlet(TodoService todoService, @ComponentImport UserManager userManager) {
    this.todoService = todoService;
    this.userManager = userManager;
 }

因此,您可以按以下方式导入活动对象:

Hence, you can import Active Objects as follows:

public TodoServiceImpl(@ComponentImport ActiveObjects ao) {
    this.ao = ao;
}

请确保不要对构造函数中的ao做任何操作,因为它尚未准备就绪!

Make sure not to do anything with ao in the constructor, since its not ready jet!

希望有帮助

这篇关于如何在Atlassian SDK中使用带有注释的Active Objects的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆