@Autowired in FXML Controller

时间:2015-07-06 20:14:12

标签: java spring dependency-injection autowired

我有一个简短的问题。我设法用xml配置文件做一些依赖注入,它工作得很好! 但是一旦我尝试注入一个FXML控制器它就不再工作了,我得到一个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>

注射点

@Autowired private MainModel iMainModel;

1 个答案:

答案 0 :(得分:0)

好的可以关闭自己找到答案:) 我在运行时使用“new”创建了FXML Controller,我补充说FXML Controller有一个单例bean,现在它确实有效!