Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Injection of custom object in JiraWebActionSupport results in NullPointerException

vvasic75 June 28, 2016

Hi there,

I have NullPointerException for my helper object when I try to inject it into WebWork action.

@Named("myWebworkAction")
public class MyWebworkAction extends JiraWebActionSupport {
    private static final long serialVersionUID = -3982259308677998254L;

    @Inject
    MyHelper myHelper;

    private final JiraAuthenticationContext jiraAuthenticationContext;

    @Inject
    public SingleCustomFieldWebworkAction(@ComponentImport final JiraAuthenticationContext jiraAuthenticationContext) {
        this.jiraAuthenticationContext = jiraAuthenticationContext;
    }

    private List<FieldDto> customFieldsDtos;

    public List<FieldDto> getCustomFieldsDtos() {
        String username = jiraAuthenticationContext.getLoggedInUser().getUsername();
        customFieldsDtos = myHelper.getUserCustomFieldDtos(username);
        return customFieldsDtos;
    }
}
@Named("myHelper")
public class MyHelper {

	private final CustomFieldManager customFieldManager;
    private final IssueManager issueManager;
    private final UserManager userManager;

    @Inject
    public MyHelper(@ComponentImport final CustomFieldManager customFieldManager, @ComponentImport final IssueManager issueManager,
            @ComponentImport final UserManager userManager) {
        this.customFieldManager = customFieldManager;
        this.issueManager = issueManager;
        this.userManager = userManager;
    }
	public List<FieldDto> getAllCustomFieldDtos(String username) {
        List<Issue> votedIssues = issueManager.getVotedIssues(userManager.getUserByName(username));
        List<CustomField> allCustomFields = customFieldManager.getCustomFieldObjects(votedIssues.get(0));
        return convertToDTOs(allCustomFields);
    }
}

Can you please help me?

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
vvasic75 June 29, 2016

I apologize for misleading you.

Since I was migrating plugin from describing components in atlassian-plugin.xml to using spring scanner and annotations, I never payed attention that I missed META-INF with spring folder and plugin-context.xml in it.

Since I had another plugin created from scratch for JIRA 7 I always had that file.

I was confused how come that the same code base did inject my components properly in plugin created for JIRA 7 and in migrating project it didn't.

I was missing this part:

Screen Shot 2016-06-29 at 3.22.00 PM.png

Sorry again and big thanks to @Jobin Kuruvilla for your response.

1 vote
Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 28, 2016

You shouldn't use Inject annotation on the Helper object definition. Inject annotation is for constructors. You can use ComponentImport annotation and inject your helper, just like you have done with JiraAuthenticationContext.

vvasic75 June 28, 2016

That is what I thought, but when I do that I have:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.example.helper.MyHelper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport(value=)}

Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 28, 2016

Try without ComponentImport. Internal components don't need that annotation.

vvasic75 June 28, 2016

On the other project I have rest resources class with end-points where I successfully Inject my other services/components like shown above. It must be that something is wrong with injection/instantiation of other beans or components further in a project (since I am migrating it from components reported in atlassian-plugin.xml to atlassian spring scanner way). I just can't see in log what went wrong during beans injection/wiring.

0 votes
Guilherme Nogueira
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 29, 2016

What if you use component accessor instead? You can use for all component imported listed. Example:

private String loggedUser = ComponentAccessor.getJiraAuthenticationContext().getUser().getUsername();

 

Sometimes I have problem with spring-scanner, if you want to use it, please, post your pom.xml

TAGS
AUG Leaders

Atlassian Community Events