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?
Community moderators have prevented the ability to post new answers.
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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=)}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try without ComponentImport. Internal components don't need that annotation.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.