Forums

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

How to find AttachmentManager using @Autowire

robert_egan_305 February 21, 2020

I have a plugin. It can find the attachment manager using

ContainerManager.getComponent("attachmentManager")

but I cannot figure out how to autowire it. The relatively straightforward

@Autowired
public MyCustomServlet(AttachmentManager attachmentManager) {

}

 Produces a stack trace that implies I need to use <component-import>, yet adding @ComponentImport did not resolve that error. I tried adding an import into my own spring xml,

<import resource="classpath:/applicationContext.xml"/>

but that did not work either. What am I missing?

1 answer

0 votes
Jack Nolddor _Sweet Bananas_
Atlassian Partner
February 21, 2020 edited

Hi robert_egan_305

 

This is what i used to do in some of my plugins:

 

@Scanned
public class MyClass
{
    protected static final Logger log = LoggerFactory.getLogger(MyClass.class);

    @ComponentImport
    private final AttachmentManager attachmentManager;

@Autowired public MyClass(AttachmentManager attachmentManager) { this.attachmentManager = attachmentManager; }
}
robert_egan_305 February 21, 2020 edited

It seems you need all 3 annotations. @Scanned, @ComponentImport, AND  @Autowired.

Thanks.

 

 

Jack Nolddor _Sweet Bananas_
Atlassian Partner
February 21, 2020

First time I deal with this "new way" of DI i found quite useful the following documentation:

 

It helps me while i was creating Announcement Banner for Confluence

Hope this help to you as well.

Suggest an answer

Log in or Sign up to answer
TAGS
Atlassian, Team '25 Europe, Atlassian conference, AI-powered teamwork, Atlassian events, keynote speakers, Barcelona tech conference, Atlassian Williams Racing, Carlos Sainz, Jenson Button, Mike Cannon-Brookes, Anu Bharadwaj, Atlassian Rovo

Atlassian Williams Racing is coming to Team '25 Europe 🏎️

Discover the teamwork and precision behind success on and off the track. See how this high-performing team makes the impossible possible. Be one of the first 100 customers to register for a chance to win 2 tickets to an Atlassian Williams 2026 race.

Register now
AUG Leaders

Atlassian Community Events