forked from RamAlapure/JavaFXSpringBootApp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
54 lines (42 loc) · 1.57 KB
/
Main.java
File metadata and controls
54 lines (42 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.codetreatise;
import javafx.application.Application;
import javafx.stage.Stage;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import com.codetreatise.config.StageManager;
import com.codetreatise.view.FxmlView;
@SpringBootApplication
public class Main extends Application {
protected ConfigurableApplicationContext springContext;
protected StageManager stageManager;
public static void main(final String[] args) {
Application.launch(args);
}
@Override
public void init() throws Exception {
springContext = springBootApplicationContext();
}
@Override
public void start(Stage stage) throws Exception {
stageManager = springContext.getBean(StageManager.class, stage);
displayInitialScene();
}
@Override
public void stop() throws Exception {
springContext.close();
}
/**
* Useful to override this method by sub-classes wishing to change the first
* Scene to be displayed on startup. Example: Functional tests on main
* window.
*/
protected void displayInitialScene() {
stageManager.switchScene(FxmlView.LOGIN);
}
private ConfigurableApplicationContext springBootApplicationContext() {
SpringApplicationBuilder builder = new SpringApplicationBuilder(Main.class);
String[] args = getParameters().getRaw().stream().toArray(String[]::new);
return builder.run(args);
}
}