How to make Component Plugin Module dependency-injected.

1. Write the below in the atlassian-plugin.xml.


<component key="helloWorldService" public="true" class="com.akira.MyHelloWorldServiceImpl">
<interface>com.akira.MyHelloWorldService</interface>
</component>

2. MyHelloWorldService

package com.akira;

public interface MyHelloWorldService {
String getMessage();
}

3. MyHelloWorldServiceImpl

package com.akira;

public class MyHelloWorldServiceImpl implements MyHelloWorldService {

public String getMessage() {
return "Hello World";
}
}

4. Use the Component Plugin Module in an ActionSupport class.

public class AkiraActionSupport extends JiraWebActionSupport {

private MyHelloWorldService _myHelloWorldService;

public String doExecute() {
System.out.println(_myHelloWorldService.getMessage());
return SUCCESS;
}
}

5. A NullPointerException occurs because the dependency-injection fails.

6. What other steps are required to make Componet Module available.

1 answer

1 accepted

0 vote

Inject it in constructor.

public class AkiraActionSupport extends JiraWebActionSupport {

    private MyHelloWorldService _myHelloWorldService;

    public AkiraActionSupport(MyHelloWorldService _myHelloWorldService){
        this.myHelloWorldService = myHelloWorldService;
    }
   
    public String doExecute() {
        System.out.println(_myHelloWorldService.getMessage());
        return SUCCESS;
    }
}

You will need component-import if you are using it in a different plugin.

Thank you very much.

I forgot how to use Springframework's dependency injection.

But I am wondering if I can inject it using Annotation Qualifier in JIRA like below.

@Autowired

@Qualifier("MyHelloWorldService")

private MyHelloWorldService _myHelloWorldService;

it seems you can. Just create custom spring-only xml definition in resource/META-INF/spring/*.xml. You can read more about it in: https://developer.atlassian.com/display/PLUGINFRAMEWORK/Advanced+Configuration+with+Spring+XML+Files Don't forget <context:annotation-config /> (as in: https://answers.atlassian.com/questions/29872/why-is-spring-autowire-not-working-for-my-jira-plugin-classes)

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Posted 8 hours ago in Jira

We want to know what Jira Service Desk apps you're using!

Hi Community! My name is Amir and I’m on the Jira Service Desk product marketing team at Atlassian. Our team would love to understand how you’re leveraging our ecosystem for Jira Service Desk. Wha...

32 views 0 5
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you