Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用javafx的Spring数据jpa_Spring_Spring Boot_Javafx 8_Openjfx_Spring Boot Jpa - Fatal编程技术网

使用javafx的Spring数据jpa

使用javafx的Spring数据jpa,spring,spring-boot,javafx-8,openjfx,spring-boot-jpa,Spring,Spring Boot,Javafx 8,Openjfx,Spring Boot Jpa,我在OpenJFX中使用SpringJPA。就是这个项目,只需在pom中添加spring启动数据jpa 然而,我的SpringJPA的开始时间是15-20秒,UI在Spring初始化之前不会显示。当用户启动应用程序时,每次都要花费很多时间 作为一种解决方法,我尝试创建一个没有Spring的简单JavaFX应用程序(使用这个演示),然后在main方法中开始使用按钮上的Spring的main方法(参见下面的示例)。这将从spring开始,但依赖项和属性并没有过时 你知道一个很好的练习方法吗?欢迎提供

我在OpenJFX中使用SpringJPA。就是这个项目,只需在pom中添加spring启动数据jpa

然而,我的SpringJPA的开始时间是15-20秒,UI在Spring初始化之前不会显示。当用户启动应用程序时,每次都要花费很多时间

作为一种解决方法,我尝试创建一个没有Spring的简单JavaFX应用程序(使用这个演示),然后在main方法中开始使用按钮上的Spring的main方法(参见下面的示例)。这将从spring开始,但依赖项和属性并没有过时

你知道一个很好的练习方法吗?欢迎提供一切帮助

多谢各位

AppBootstrap(Java+OpenJFX) 应用程序(SpringJPA+JavaFXWeaver)
启动JPA驱动的应用程序会增加ApplicationContext的加载时间。虽然您可以通过不检查或创建数据库方案(例如通过设置
hibernate.hbm2ddl.auto=none
)来加快速度,但这并不是最好的选择

根据设计,主阶段在加载ApplicationContext后显示,因为它应该能够被注入依赖项

我推荐的最佳实践是在加载ApplicationContext时使用闪屏。这有点棘手,因为您有单独的线程,但大致如下所示:

创建一个启动窗口

公共类Splash{
专用静态最终int飞溅_宽度=200;
专用静态最终内部飞溅高度=200;
私人最终父母;
私人最后阶段;
公共喷溅(){
this.stage=新阶段();
舞台设置宽度(飞溅宽度);
舞台设置高度(飞溅高度);
Label progressText=新标签(“应用程序加载…”);
VBox splashLayout=新的VBox();
喷溅布局。设置对齐(位置中心);
splashLayout.getChildren().addAll(progressText);
progressText.setAlignment(位置中心);
splashLayout.setStyle(
“-fx填充:5;”+
“-fx背景色:白色;”+
“-fx边框宽度:5;”+
“-fx边框颜色:白色;”
);
setEffect(新的DropShadow());
this.parent=splashLayout;
}
公开展览({
场景splashScene=新场景(父场景);
舞台风格(舞台风格。未装饰);
最终矩形2D边界=Screen.getPrimary().getBounds();
舞台场景(喷溅场景);
stage.setX(bounds.getMinX()+bounds.getWidth()/2-SPLASH_WIDTH/2.0);
stage.setY(bounds.getMinY()+bounds.getHeight()/2-SPLASH_HEIGHT/2.0);
stage.show();
}
公共空间隐藏(){
stage.toFront();
FadeTransition fadeSplash=新的FadeTransition(持续时间。秒(0.3),父级);
FadesFlash.setFromValue(1.0);
fadeSplash.setToValue(0.0);
setOnFinished(actionEvent->stage.hide());
flash.play();
}
}
初始化应用程序

公共类SpringbootJavaFxApplication扩展应用程序{
私有配置应用程序上下文上下文;
类ApplicationContextLoader扩展任务{
私人最后阶段初级阶段;
ApplicationContextLoader(阶段primaryStage){
this.primaryStage=primaryStage;
}
@凌驾
受保护的无效调用(){
ApplicationContextInitializer初始值设定项=
上下文->{
registerBean(Application.class,()->SpringbootJavaFxApplication.this);
registerBean(Stage.class,()->primaryStage);
registerBean(Parameters.class,
SpringbootJavaFxApplication.this::getParameters);//用于演示,实际上不需要
};
SpringbootJavaFxApplication.this.context=新的SpringApplicationBuilder()
.sources(JavaFxSpringbootDemo.class)
.初始值设定项(初始值设定项)
.run(getParameters().getRaw().toArray(新字符串[0]);
返回null;
}
}
@凌驾
公共无效开始(阶段primaryStage){
var splash=新splash();
splash.show();
最终ApplicationContextLoader ApplicationContextLoader=新ApplicationContextLoader(primaryStage);
applicationContextLoader.stateProperty().addListener((ObservalEvalue、oldState、newState)->{
if(newState==Worker.State.successed){
PublisheEvent(新阶段AdyeEvent(初级阶段));
splash.hide();
}
});
新线程(applicationContextLoader).start();
}
@凌驾
公共停车场(){
this.context.close();
Platform.exit();
}
}

非常感谢。这是一个很好的解决方案,这正是搜索的目的。。伟大的
public class AppBootstrap extends Application {

    @Override
    public void start(Stage primaryStage) {

        Button btn = new Button();

        // start spring jpa main method
        btn.setOnAction(event -> App.main(new String[]{""})); 

        StackPane root = new StackPane();
        root.getChildren().add(btn);

        primaryStage.setScene(new Scene(root, 300, 250));
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch();
    }
}
@SpringBootApplication
public class App {
    public static void main(String[] args) {
        Application.launch(SpringbootJavaFxApplication.class, args);
    }
}