我有一个简短的问题。我设法使用 xml 配置文件进行一些依赖项注入(inject),效果非常好! 但是一旦我尝试注入(inject) FXML Controller ,它就不再工作,并且我收到 NullPointerException...
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="iMainGUIHandler" class="de.vibrating_earth.main.MainGUIHandler" scope="singleton" autowire="byName"></bean>
<bean id="iMainModel" class="de.vibrating_earth.main.MainModel" scope="singleton" autowire="byName"></bean>
</beans>
注入(inject)点
@Autowired 私有(private)MainModel iMainModel;
最佳答案
好的,可以关闭,我自己找到了答案:) 我在运行时使用“new”创建了 FXML Controller ,我添加了 FXML Controller 有一个单例 bean,现在它可以工作了!
关于java - FXML Controller 中的 @Autowired,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31254786/