一、引入依赖:

新建Java SpringBoot 项目后在 pom.xml 文件中引入 JavaFX:

<dependencies>
	<!-- SpringBoot集成JavaFX -->
	<dependency>
		<groupId>de.roskenet</groupId>
		<artifactId>springboot-javafx-support</artifactId>
		<version>2.1.6</version>
	</dependency>

	<!-- SpringBoot集成JavaFX测试类 -->
	<dependency>
		<groupId>de.roskenet</groupId>
		<artifactId>springboot-javafx-test</artifactId>
		<version>1.3.0</version>
		<scope>test</scope>
	</dependency>
</dependencies>

二、简单Demo:

a、项目总览:

src
 |-- main
	  |-- java
	  |		|-- com
	  |			  |-- demo
	  |					|-- controller
	  |					|		|-- ModelViewController.java
	  |					|-- view
	  |					|	  |-- ModelView.java
	  |					|-- DemoApplication.java
	  |-- resources
			  |-- css
			  |-- view
					|-- ModelView.fxml

b、启动类:

@SpringBootApplication
public class DemoApplication extends AbstractJavaFxApplicationSupport {

    public static void main(String[] args) {
        launch(DemoApplication.class, ModelView.class, args);
    }

    @Override
    public void start(Stage stage) throws Exception {
		super.start(stage);
    }
}

c、ModelViewController.java

@FXMLController
public class MainViewController implements Initializable {
	
	@FXML
    private AnchorPane container;
	
	@Override
    public void initialize(URL location, ResourceBundle resources) {
        // container 初始化操作
    }
}

d、ModelView.java

@FXMLView(value = "/view/ModelView.fxml", title = "ModelView")
public class ModelView extends AbstractFxmlView {

}

e、ModelView.fxml

<AnchorPane fx:id="container" prefHeight="600" prefWidth="800" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.demo.controller.ModelViewController">
	<children>
	
	</children>
</AnchorPane>