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_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
February 21, 2020

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

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

Thanks.

 

 

Jack Nolddor _Sweet Bananas_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
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
AUG Leaders

Atlassian Community Events