[英]Nullpointer Exception when trying to access Injected Bean
I have a maven multi module project. 我有一个Maven多模块项目。 When trying to Access a injected bean i get a Nullpointer Exception.
当尝试访问注入的bean时,我得到了Nullpointer异常。
this is the main Function that startsthe application 这是启动应用程序的主要功能
public class App {
public static void main(String[] args) {
System.out.println("Startpoint");
DecisionMaker decisionMaker = new DecisionMaker();
decisionMaker.run();
}
}
this is what i do in the DecisionMaker 这就是我在DecisionMaker中所做的
public class DecisionMaker {
@Inject
GameListener gm;
@Inject
BasicProductionManager basicProductionManager;
public DecisionMaker() {
System.out.println("this is the decisionmaker");
System.out.println(gm.toString());
}
so this is not an bean but a normal pojo 所以这不是豆子,而是普通的pojo
the gamelistener is a Applicationscoped bean which i want to inject. gamelistener是我要注入的Applicationscoped bean。
@Named
@ApplicationScoped
public class GameListener extends DefaultBWListener {
@Inject
Event<OnFrameEvent> onFrameEvent;
public Mirror mirror = new Mirror();
public Game game;
public Player self;
@PostConstruct
public void init() {
System.out.println("init listener");
}
the nullpointer gets thrown in the constructor of the DecisionMaker. 空指针将被抛出到DecisionMaker的构造函数中。 The @PostConscrutct init method is not called
@PostConscrutct初始化方法未调用
I looked into similar question but all i found is that i needthe PostConstruct method which i already have. 我调查了类似的问题,但发现的全部是我需要已经拥有的PostConstruct方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.