Bamboo AgentManager dependency injection not working

Hello,
I just created a bamboo plugin skeleton by this command “atlas-create-bamboo-plugin”
and I created a rest API module.
But after that, I use Agent manager and generate a setter for that so that spring can inject the dependency but it is still null

import com.atlassian.bamboo.buildqueue.manager.AgentManager;
import com.atlassian.plugin.spring.scanner.annotation.component.Scanned;
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
import com.atlassian.plugins.rest.common.security.AnonymousAllowed;
import org.springframework.beans.factory.annotation.Autowired;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

/**
 * A resource of message.
 */
@Path("/message")
public class AgfentApi {
    public void setAgentManager(AgentManager agentManager) {
        this.agentManager = agentManager;
    }

    private AgentManager agentManager;


    @GET
    @AnonymousAllowed
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response getMessage()
    {
        if(agentManager!=null)
       return Response.ok(new AgfentApiModel("success")).build();
        else
            return Response.ok(new AgfentApiModel("not success")).build();


    }
}

I am getting the output as “not success” .Output for the api call

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<message>
    <value>not success</value>
</message>

I am using bamboo 6.8.0 version plugin skeleton.
Is this is any bug or I works fine for others??

Hi - looks like you are importing the required spring scanner annotations, but do not use them - try:

/**
 * A resource of message.
 */
@Scanned
@Path("/message")
public class AgfentApi {
    @Autowired
    public void setAgentManager(@ComponentImport AgentManager agentManager) {
        this.agentManager = agentManager;
    }
...

(Depending on the spring scanner version in use, you might not need the @Scanned one - see Atlassian Spring Scanner for details …)

1 Like

@hopel Thank you for your help it works like a charm.
Thank you again i have spended a lot of time on this.