如何在atlassian sdk中使用带有注释的活动对象

时间:2016-06-29 10:35:57

标签: jira

我做Jira插件,我需要使用Active Object。 (Jira v7.1.8) 但在官方文档中已经过时了。它是用xml编写的,但如果我理解正确的话,现在使用的是Atlassian Spring Scanner(我使用的是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, 在控制台我得到这个:

[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)

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

1 个答案:

答案 0 :(得分:0)

经过几周的网络搜索和大量试用后,我终于得到了正式的Active Objects教程,可以使用最新版本的Jira(7.1.2)和spring-scanner 2.0支持。

您可以在GitHub上找到完整的代码示例,但以下是其中的要点:

正确宣布您的权利

 <!-- 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>

**春天背景** 您还需要使用/resources/META-INF/spring/plugin-context.xml

配置spring
<?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 Bean

然后,您可以使用@Component标记您的java类以进行依赖注入。

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

您自己的bean将自动注入,外部bean必须与@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;
 }

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

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

请确保不要在构造函数中对ao执行任何操作,因为它没有准备好喷射!

希望有所帮助