Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Custom REST API problem with @Inject @Named, not showing my apis at all

jira jira May 9, 2020

I am developing rest plugin for jira atlassian and I have this kind of problem. every time I want that my apis are showing up I need to add empty constructor to my new api in this format

 

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();
    }
}

 

However what I want is something like this 

@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();
    }
}

with injected constructor and @Scanned. I get this error when I am using the second version of code with @Named in ImportIssuesAction. I have tried also @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: {}

  The others custom implemented working api have similar injected constructor and using annotations @Scanned or @Named. I need my api real-time getting information from class. However currently I am getting NullPointerException from empty constructor in rest of my public getter getIssueNumber. When I am using  @Named @Inject combination the all of my custom apis are hidden.  I have tried also 

<component-import key="importIssuesAction" interface="sk.eea.jira.telecom.extension.action."/>

in atlassian-plugin.xml.  In atlassian-plugin I have also 

<rest name="CSMT Rest Resource" key="csmt-rest-resource" path="/csmt" version="1.0">
<description>CSMT Rest Resources</description>
</rest>

Can somebody help with implementing custom REST API? 

1 answer

0 votes
Mohamed Benziane
Community Champion
May 9, 2020

Hi,

Did you look a the community developer, i think you will find more answer. You can also post your question there.

https://community.developer.atlassian.com/

jira jira May 9, 2020

Hi thanks for answer, I will try luck on developer community too.

Suggest an answer

Log in or Sign up to answer