The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with @Inject

lpopek
January 30, 2019

Hello,
I have 3 classes.
One class is annotated as @Component and @Named. In second class I use @Scanned annotation and can inject first class with @Inject below constructor. Example:

FirstClass firstClass;

@Inject
public SecondClass(FirstClass firstClass){
           this.firstClass = firstClass;
}

Everything works. But… If I try also parallel inject first class to third class as above I had exception

 _[o.a.c.c.C.[.[localhost].[/jira].[action]] Servlet.service() for servlet [action] in context with path [/jira] threw exception [java.lang.NullPointerException] with root cause_
_[INFO] [talledLocalContainer] java.lang.NullPointerException_

I passed this problem through create object of first class in constructor like:

FirstClass firstClass;

public ThirdClass(FirstClass firstClass){
this.firstClass = new FirstClass();
}

But… It’s wrong solution. How to fix it with normal adnotation @Inject or something other?

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Answer accepted
Alexey Matveev
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 Champions.
January 30, 2019

Hello,

You should also put the Scanned annotation to the third class and use Inject in the constructor.

lpopek
January 31, 2019

In Third Class I already have @Inject and @Scanned annotations. Third Class dont implement anything and extends.   

lpopek
January 31, 2019

@Scanned
public class ThirdClass {
FirstClass firstClass;

@Inject
public ThirdClass(FirstClass firstClass;) {
    this.firstClass = firstClass;
}
lpopek
January 31, 2019

Problem is resolved. I used Fabric Pattern and in this case is something otherwise. Thanks for help.

TAGS
AUG Leaders

Atlassian Community Events