Spring integration

218 views
Skip to first unread message

Hoby

unread,
Jul 14, 2014, 12:15:12 PM7/14/14
to dataf...@googlegroups.com
Hi,
Is it possible to inject Spring bean (back-end service) in Datafx Controller. Our back-end use Spring/Mybatis and we have Spring/Javafx in the front. Now we'd like to use Datafx Flow in the front but I'm not sure if it is possible.

Thanks
Hoby

Hendrik Ebbers

unread,
Jul 16, 2014, 4:08:40 PM7/16/14
to dataf...@googlegroups.com
Hi,
I don't know why this shouldn't be possible :)
Maybe you can post an example and we can discuss the integration.

Hoby

unread,
Jul 16, 2014, 6:51:52 PM7/16/14
to dataf...@googlegroups.com
OK. 
I added a Spring Service to your datafx-tutorial-5 project (see code below) and it works fine when I use applicationContext.getBean spring method to get bean.

@FXMLController("wizardView1.fxml")
public class WizardView1Controller {
@FXML
private Label view1Label;

MessageService service;

@PostConstruct
public void init() {
service = SpringContext.getApplicationContext().getBean(MessageService.class);
view1Label.setText(service.getMessage());
}

}

@Service
public class MessageService {
public String getMessage() {
return "message";
}
}

wizardView1.fxml

<Label fx:id="view1Label"  xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
    <font>
        <Font size="24.0"/>
    </font>
</Label>


Have you an idea how do I do if I want to use annotation @Autowired MessageService now.

Thanks
Hoby

Hendrik Ebbers

unread,
Jul 17, 2014, 3:43:24 PM7/17/14
to dataf...@googlegroups.com
Hi,

Actually this isn't supported. But it is no problem to add the support :)
DataFX contains a PlugIn API that used SPI to integrate new Annotations to inject data to the controller.
Please do the following: create an issue at https://bitbucket.org/datafx/datafx/ and post the example in the issue. Then I will try to create a Spring injection plugin the next weeks. If you want to do this on your own you can do the following:

Hoby

unread,
Jul 18, 2014, 4:18:13 AM7/18/14
to dataf...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages