在JIRA系统中,通过注解的方式 -------父插件调用子插件的方法

在JIRA系统中,通过注解的方式 -------父插件调用子插件的方法
子插件:
将父插件需要引用Service、Entity、ServiceImp(Service实现类)暴露出来,最主要是ServiceImp类
代码如下:
Service

package com.shdsd.plugin.teamBase.service;
import com.atlassian.jira.util.PageRequest;
import com.atlassian.jira.util.json.JSONException;
import com.shdsd.plugin.teamBase.ao.entity.WiseTeamEntity;
import com.shdsd.plugin.teamBase.rest.vo.WiseTeamBean;
import java.util.Map;
/**
 * 团队配置
 */
public interface WiseTeamService {
    /**
     * 查询所有的团队配置
     *
     * @return
     */
    WiseTeamEntity[] getWiseTeams();
}

ServiceImp类:

package com.shdsd.plugin.teamBase.service.impl;
import com.atlassian.activeobjects.external.ActiveObjects;
import com.atlassian.crowd.embedded.api.Group;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.project.Project;
import com.atlassian.jira.project.ProjectManager;
import com.atlassian.jira.security.groups.GroupManager;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.user.util.UserManager;
import com.atlassian.jira.util.json.JSONException;
import com.atlassian.jira.util.json.JSONObject;
import com.atlassian.plugin.spring.scanner.annotation.export.ExportAsService;
import com.shdsd.plugin.teamBase.ao.entity.ReportSettingEntity;
import com.shdsd.plugin.teamBase.ao.entity.WiseTeamEntity;
import com.shdsd.plugin.teamBase.ao.entity.WiseTeamProjectEntity;
import com.shdsd.plugin.teamBase.ao.entity.WiseTeamUserEntity;
import com.shdsd.plugin.teamBase.ao.helper.DBParamBuilder;
import com.shdsd.plugin.teamBase.rest.vo.ProjectBean;
import com.shdsd.plugin.teamBase.rest.vo.UserBean;
import com.shdsd.plugin.teamBase.rest.vo.WiseTeamBean;
import com.shdsd.plugin.teamBase.service.WiseTeamProjectService;
import com.shdsd.plugin.teamBase.service.WiseTeamService;
import com.shdsd.plugin.teamBase.service.WiseTeamUserService;
import com.shdsd.plugin.teamBase.util.DsdApp;
import com.shdsd.plugin.teamBase.util.PageHelper;
import com.shdsd.plugin.teamBase.util.TeamAuthHelper;
import com.shdsd.plugin.teamBase.util.convert.ProjectConvert;
import com.shdsd.plugin.teamBase.util.convert.UserConvert;
import org.apache.commons.lang.ArrayUtils;
import com.atlassian.jira.util.Page;
import com.atlassian.jira.util.PageRequest;
import com.atlassian.jira.util.Pages;
import lombok.extern.slf4j.Slf4j;
import net.java.ao.DBParam;
import net.java.ao.Query;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import com.shdsd.plugin.teamBase.service.base.BaseService;
import java.util.*;
import javax.inject.Inject;

@Slf4j
@ExportAsService({WiseTeamService.class})
@Service
public class WiseTeamServiceImpl extends BaseService<WiseTeamEntity> implements WiseTeamService {
    private final WiseTeamProjectService wiseTeamProjectService;
    private final WiseTeamUserService wiseTeamUserService;
    private final GroupManager groupManager = ComponentAccessor.getGroupManager();
    @Inject
    public WiseTeamServiceImpl( ActiveObjects ao, WiseTeamProjectService wiseTeamProjectService,
                               WiseTeamUserService wiseTeamUserService
    ) {
        super(ao);
        this.wiseTeamProjectService = wiseTeamProjectService;
        this.wiseTeamUserService = wiseTeamUserService;
    }

    @Override
    public WiseTeamEntity[] getWiseTeams() {
        return ao.findLogical(WiseTeamEntity.class, Query.select());
    }
}

pom文件配置(Pom文件中的 Export-Package 就是存放需要给父插件进行引用的类):

<build>
       <plugins>
            <plugin>
                <groupId>org.sonarsource.scanner.maven</groupId>
                <artifactId>sonar-maven-plugin</artifactId>
                <version>3.6.0.1398</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.5</version>
                <configuration>
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.atlassian.maven.plugins</groupId>
                <artifactId>jira-maven-plugin</artifactId>
                <version>${amps.version}</version>
                <extensions>true</extensions>
                <configuration>
                    <productVersion>${jira.version}</productVersion>
                    <productDataVersion>${jira.version}</productDataVersion>
                    <jvmArgs>-Xms1g -Xmx1500m -XX:MaxPermSize=1g -XX:-UseGCOverheadLimit -server  -Datlassian.mail.senddisabled=false</jvmArgs>
                    <enableQuickReload>true</enableQuickReload>
                    <allowGoogleTracking>false</allowGoogleTracking>
                    <skipRestDocGeneration>true</skipRestDocGeneration>
                    <instructions>
                        <Atlassian-Plugin-Key>${atlassian.plugin.key}</Atlassian-Plugin-Key>
                        <!-- Add package import here -->
                        <Atlassian-Scan-Folders>META-INF/plugin-descriptors</Atlassian-Scan-Folders>
                        <Export-Package>
                            com.shdsd.plugin.teamBase.ao.entity,
                            com.shdsd.plugin.teamBase.service,
                            com.shdsd.plugin.teamBase.service.impl,
                        </Export-Package>
                        <Import-Package>
                            <!-- imports -->
                            org.springframework.osgi.*;resolution:="optional",
                            org.eclipse.gemini.blueprint.*;resolution:="optional",
                            <!-- spring imports -->
                            org.springframework.aop,
                            org.springframework.core,
                            <!-- jira stuff -->
                            com.atlassian.jira.plugin.webfragment.conditions,
                            com.atlassian.jira.issue.customfields.searchers,
                            com.atlassian.jira.jql.operand,
                            <!-- required for spring lifecycle annotations -->
                            <!--javax.annotation,-->
                            <!-- exclude stuff for querydsl pocketknife -->
                            !net.sf.cglib.proxy,
                            !org.jvnet.hudson.annotation_indexer,
                            <!-- everything else -->
                            *;resolution:=optional
                        </Import-Package>
                        <!--<Require-Bundle>org.apache.felix.framework</Require-Bundle>-->
                        <!-- 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>
            </plugin>
        </plugins>
    </build>

父插件引用如下 :
pom文件配置(Import-Package将需要引入的类写在此处,pom文件还需要配置子插件的依赖):

<dependency>
     <groupId>com.shdsd.plugin</groupId>
     <artifactId>teamBase</artifactId>
     <version>${teamBase.version}</version>
     <scope>provided</scope>
</dependency>
 <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.5</version>
                <configuration>
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.atlassian.maven.plugins</groupId>
                <artifactId>jira-maven-plugin</artifactId>
                <version>${amps.version}</version>
                <extensions>true</extensions>
                <configuration>
                    <productVersion>${jira.version}</productVersion>
                    <productDataVersion>${jira.version}</productDataVersion>
                    <jvmArgs>-Xms1g -Xmx1500m -XX:MaxPermSize=1g -XX:-UseGCOverheadLimit -server  -Datlassian.mail.senddisabled=false</jvmArgs>
                    <enableQuickReload>true</enableQuickReload>
                    <allowGoogleTracking>false</allowGoogleTracking>
                    <skipRestDocGeneration>true</skipRestDocGeneration>
                    <instructions>
                        <Atlassian-Plugin-Key>${atlassian.plugin.key}</Atlassian-Plugin-Key>
                        <!-- Add package import here -->
                        <Atlassian-Scan-Folders>META-INF/plugin-descriptors</Atlassian-Scan-Folders>
                        <Import-Package>
                            <!-- imports -->
                            org.springframework.osgi.*;resolution:="optional",
                            org.eclipse.gemini.blueprint.*;resolution:="optional",
                            <!-- spring imports -->
                            org.springframework.aop,
                            org.springframework.core,
                            <!-- jira stuff -->
                            com.atlassian.jira.plugin.webfragment.conditions,
                            com.atlassian.jira.issue.customfields.searchers,
                            com.atlassian.jira.jql.operand,
                            <!-- required for spring lifecycle annotations -->
                            <!--javax.annotation,-->
                            <!-- exclude stuff for querydsl pocketknife -->
                            !net.sf.cglib.proxy,
                            !org.jvnet.hudson.annotation_indexer,
                            com.shdsd.plugin.teamBase.ao.entity;resolution:="optional",
                            com.shdsd.plugin.teamBase.service;resolution:="optional",
                            com.shdsd.plugin.teamBase.service.impl;resolution:="optional",
                            <!-- everything else -->
                            *;resolution:=optional
                        </Import-Package>
                        <!--<Require-Bundle>org.apache.felix.framework</Require-Bundle>-->
                        <!-- Ensure plugin is spring powered -->
                        <Spring-Context>*</Spring-Context>
                    </instructions>

                    <bundledArtifacts>
                        <bundledArtifact>
                            <groupId>com.shdsd.plugin</groupId>
                            <artifactId>teamBase</artifactId>
                            <version>${teamBase.version}</version>
                        </bundledArtifact>
                    </bundledArtifacts>
                    <pluginDependencies>
                        <pluginDependency>
                            <groupId>com.shdsd.plugin</groupId>
                            <artifactId>teamBase</artifactId>
                        </pluginDependency>
                    </pluginDependencies>
                </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>
                    <scannedDependencies>
                        <dependency>
                            <groupId>com.atlassian.plugin</groupId>
                            <artifactId>atlassian-spring-scanner-external-jar</artifactId>
                        </dependency>
                        <dependency>
                            <groupId>com.atlassian.pocketknife</groupId>
                            <artifactId>atlassian-pocketknife-querydsl</artifactId>
                        </dependency>
                    </scannedDependencies>
                    <verbose>false</verbose>
                </configuration>
            </plugin>
        </plugins>
    </build>

在父插件中引用时,直接用注解的方式注入service类会报如下错误:

package com.shdsd.plugin.organizationPro.rest;
import com.alibaba.fastjson.JSONArray;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.config.properties.APKeys;
import com.atlassian.jira.project.ProjectManager;
import com.google.common.collect.Lists;
import com.shdsd.plugin.organizationPro.ao.entity.DepartmentEntity;
import com.shdsd.plugin.organizationPro.core.manager.DsdFilterManager;
import com.shdsd.plugin.organizationPro.core.manager.DsdProjectManager;
import com.shdsd.plugin.organizationPro.core.report.QueryCondition;
import com.shdsd.plugin.organizationPro.core.report.ReportManager;
import com.shdsd.plugin.organizationPro.core.report.workReportExport.WorkReportCsvExport;
import com.shdsd.plugin.organizationPro.data.vo.*;
import com.shdsd.plugin.organizationPro.premisson.RequirePermissions;
import com.shdsd.plugin.organizationPro.rest.convert.ProjectConvert;
import com.shdsd.plugin.organizationPro.rest.convert.UserConvert;
import com.shdsd.plugin.organizationPro.service.DepartmentService;
import com.shdsd.plugin.organizationPro.service.ReportService;
import com.shdsd.plugin.organizationPro.util.Resp;
import com.shdsd.plugin.teamBase.service.WiseTeamService;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.StringUtils;
import javax.inject.Inject;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
import static com.shdsd.plugin.organizationPro.ao.constant.PermissionEnum.Report.*;
import static com.shdsd.plugin.organizationPro.ao.constant.PermissionEnum.REPORT;

/**
 * report
 */
@Path("/report")
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
@RequirePermissions({REPORT})
public class WorkReportResource {
    private final ReportService reportService;
    private final DepartmentService departmentService;
    private final DsdProjectManager dsdProjectManager;
    private final DsdFilterManager dsdFilterManager;
    private final ReportManager reportManager;
    @ComponentImport
    private final WiseTeamService wiseTeamService;

    @Inject
    public WorkReportResource(ReportService reportService, DepartmentService departmentService, DsdProjectManager dsdProjectManager, DsdFilterManager dsdFilterManager, ReportManager reportManager) {
        this.reportService = reportService;
        this.departmentService = departmentService;
        this.dsdProjectManager = dsdProjectManager;
        this.dsdProjectManager = dsdProjectManager;
        this.dsdFilterManager = dsdFilterManager;
        this.reportManager = reportManager;
        this.wiseTeamService = wiseTeamService;
    }
}

错误:

Caused by: java.lang.ClassNotFoundException: com.shdsd.plugin.teamBase.service.WiseTeamService not found by com.shdsd.plugin.organizationPro [237]
Caused by: java.lang.ClassNotFoundException: com.shdsd.plugin.teamBase.service.WiseTeamService not found by com.shdsd.plugin.organizationPro 

解决办法是:
不采用注解注入的方式
直接在需要的地方调用某个类的方法即可

ComponentAccessor.getOSGiComponentInstanceOfType(xxx.class).方法名
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值