Che Veyo
Che Veyo

Reputation: 385

@Autowired in FXML Controller

I got a short question. I managed to do some dependency injections with a xml config file, it worked perfectly! But once i try to inject into an FXML Controller it doesnt work anymore and i am getting a 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>

Injection Point

@Autowired private MainModel iMainModel;

Upvotes: 0

Views: 163

Answers (1)

Che Veyo
Che Veyo

Reputation: 385

Ok can be closed found the answer by myself :) I created the FXML Controller at runtime with "new", i added the FXML Controller has an singleton beans and now it does work!

Upvotes: 1

Related Questions