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?
Hello,
You should also put the Scanned annotation to the third class and use Inject in the constructor.
Want to make your everyday Community actions directly contribute to reforestation? The Atlassian Community can achieve this goal by liking a post, attending an ACE, sending your peers kudos, and so much more!
Help us plant more trees
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.