Application入口改造
实现接口CommandLineRunner,并且重写run()方法,便可以在springboot启动时同时运行一段方法,
import javafx.application.Application;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class TestApplication implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(TestApplication .class, args);
}
@Override
public void run(String... args) throws Exception {
Application.launch(MainApp.class, args);
}
}
创建窗体程序
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
public class MainApp extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
AnchorPane anchorPane=new AnchorPane();
Scene scene=new Scene(anchorPane, 200, 150);
primaryStage.setScene(scene);
primaryStage.show();
}
}
运行效果