I am wondering why dependency injection with setter for ActiveObjects is not working and why I can't retrieve it via the ComponentManager. I made a test with the constructor it is working. For the other confluence component (like PageManager and so on) I don't have any proble.
Here is the relevant part of my atlassian-plugin.xml:
<!-- Servlets --> <servlet name="DocumentFormServlet" key="DocumentFormServlet" class="com.arhs.jaspers.confluence.plugin.servlet.document.DocumentUploadServlet"> <description>A servlet to create new documents</description> <url-pattern>/createDocument</url-pattern> </servlet> <!-- Active objects --> <component-import key="ao" name="Active Objects service" interface="com.atlassian.activeobjects.external.ActiveObjects"> <description>Component to access Active Objects functionality from the plugin</description> </component-import> <ao key="ao-module"> <description>The module configuring the Active Objects service used by this plugin </description> <entity>com.arhs.jaspers.confluence.plugin.model.Category</entity> <entity>com.arhs.jaspers.confluence.plugin.model.Document</entity> <entity>com.arhs.jaspers.confluence.plugin.model.Rating</entity> <entity>com.arhs.jaspers.confluence.plugin.model.Keyword</entity> </ao> <!-- Support for transaction --> <component key="tx-processor" name="Transactional Annotation Processor" class="com.atlassian.activeobjects.external.TransactionalAnnotationProcessor"> <decription>Processes @Transactional annotations.</decription> </component>
Here is the relevant part of my java code:
public class DocumentUploadServlet extends HttpServlet{ public ActiveObjects ao; public void initAo(){ //Throw component not found exception ao = ContainerManager.getComponent("ao",ActiveObjects.class); } //Never called public setAo(ActiveObjects ao){ this.ao = ao; } }
Anybody has an idea why I have suchn an error?
Community moderators have prevented the ability to post new answers.
ContainerManager only works for components exposed by the host application. ActiveObjects is exposed by another plugin so that won't work. You need to use contructor injection instead of setter injection to get access to the ActiveObjects component
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.