jira rest预计至少有1个Bean符合这个依赖关系的autowire候选资格。

问题描述 投票:0回答:1

我正在开发jira atlassian的rest插件,我遇到了这样的问题,每次我想让我的apis显示出来,我需要在我的新api中添加空的构造函数,格式是这样的

import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

@Path("/import-issues")
public class ImportIssuesRestResource {
    private ImportIssuesAction importIssuesAction;

    public ImportIssuesRestResource() {
    }

    public ImportIssuesRestResource(final ImportIssuesAction importIssuesAction) {
        this.importIssuesAction = importIssuesAction;
    }

    @GET
    @Path("issueNumber")
    @Produces(MediaType.APPLICATION_JSON)
    public Response getFields() {
        return Response.ok().entity(importIssuesAction.getIssueNumber()).build();
    }
}

然而,我想要的是这样的东西

@Scanned
@Path("/import-issues")
public class ImportIssuesRestResource{
    private ImportIssuesAction importIssuesAction;

    @Inject
    public ImportIssuesRestResource(final ImportIssuesAction importIssuesAction) {
        this.importIssuesAction = importIssuesAction;
    }

    @GET
    @Path("issueNumber")
    @Produces(MediaType.APPLICATION_JSON)
    public Response getFields() {
        return Response.ok().entity(importIssuesAction.getIssueNumber()).build();
    }
}

与注入的构造函数和@Scanned。当我使用第二个版本的代码时,我得到了这个错误。

 Error creating bean with name 'rest.ImportIssuesRestResource': Unsatisfied dependency expressed through constructor argument with index 0 of type [action.ImportIssuesAction] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}

其他的api也有类似的注入构造函数和使用@Scanned或@Named的注解。我需要我的api从类中实时获取信息。但是目前我在我的公共getIssueNumber的其余部分得到NullPointerException。我在ImportIssuesAction类中使用了@Named。

java rest jira
1个回答
0
投票

看起来ImportIssuesAction在你的atlassian-plugin.xml中没有被声明为一个组件。https:/community.atlassian.comt5Answers-Developer-QuestionsComponents-injection-with-Spring-Scannerqaq-p553801。

© www.soinside.com 2019 - 2024. All rights reserved.