Skip to content

Commit 10ae731

Browse files
committed
JavaFX Spring Boot CRUD with FXML.
0 parents  commit 10ae731

File tree

24 files changed

+1438
-0
lines changed

24 files changed

+1438
-0
lines changed

.classpath

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" output="target/classes" path="src/main/java">
4+
<attributes>
5+
<attribute name="optional" value="true"/>
6+
<attribute name="maven.pomderived" value="true"/>
7+
</attributes>
8+
</classpathentry>
9+
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
10+
<attributes>
11+
<attribute name="maven.pomderived" value="true"/>
12+
</attributes>
13+
</classpathentry>
14+
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
15+
<attributes>
16+
<attribute name="optional" value="true"/>
17+
<attribute name="maven.pomderived" value="true"/>
18+
</attributes>
19+
</classpathentry>
20+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
21+
<attributes>
22+
<attribute name="maven.pomderived" value="true"/>
23+
</attributes>
24+
</classpathentry>
25+
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
26+
<attributes>
27+
<attribute name="maven.pomderived" value="true"/>
28+
</attributes>
29+
</classpathentry>
30+
<classpathentry kind="output" path="target/classes"/>
31+
</classpath>

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/target/
2+
3+
.settings/

.project

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>JavaFXSpringBootApp</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.wst.common.project.facet.core.builder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.jdt.core.javabuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.springframework.ide.eclipse.core.springbuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
<buildCommand>
24+
<name>org.eclipse.m2e.core.maven2Builder</name>
25+
<arguments>
26+
</arguments>
27+
</buildCommand>
28+
</buildSpec>
29+
<natures>
30+
<nature>org.springframework.ide.eclipse.core.springnature</nature>
31+
<nature>org.eclipse.jdt.core.javanature</nature>
32+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
33+
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
34+
</natures>
35+
</projectDescription>

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# JavaFXSpringBoootIntegration
2+
JavaFX Spring Boot Integration

pom.xml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.codetreatise</groupId>
7+
<artifactId>JavaFXSpringBootApp</artifactId>
8+
<packaging>jar</packaging>
9+
<version>1.0</version>
10+
11+
<name>JavaFXSpringBootApp</name>
12+
13+
<parent>
14+
<groupId>org.springframework.boot</groupId>
15+
<artifactId>spring-boot-starter-parent</artifactId>
16+
<version>1.5.2.RELEASE</version>
17+
<relativePath/> <!-- lookup parent from repository -->
18+
</parent>
19+
20+
<properties>
21+
<!-- <mainClass>com.codetreatise.MainApp</mainClass> -->
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24+
<java.version>1.8</java.version>
25+
</properties>
26+
27+
<dependencies>
28+
<dependency>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot-starter-aop</artifactId>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.springframework.boot</groupId>
34+
<artifactId>spring-boot-starter-cache</artifactId>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.springframework.boot</groupId>
38+
<artifactId>spring-boot-starter-data-jpa</artifactId>
39+
</dependency>
40+
<dependency>
41+
<groupId>org.springframework.boot</groupId>
42+
<artifactId>spring-boot-starter-security</artifactId>
43+
</dependency>
44+
45+
<dependency>
46+
<groupId>mysql</groupId>
47+
<artifactId>mysql-connector-java</artifactId>
48+
<scope>runtime</scope>
49+
</dependency>
50+
<dependency>
51+
<groupId>org.springframework.boot</groupId>
52+
<artifactId>spring-boot-starter-test</artifactId>
53+
<scope>test</scope>
54+
</dependency>
55+
</dependencies>
56+
57+
<build>
58+
<plugins>
59+
<plugin>
60+
<groupId>org.springframework.boot</groupId>
61+
<artifactId>spring-boot-maven-plugin</artifactId>
62+
</plugin>
63+
<plugin>
64+
<groupId>org.apache.maven.plugins</groupId>
65+
<artifactId>maven-compiler-plugin</artifactId>
66+
<configuration>
67+
<showDeprecation>true</showDeprecation>
68+
</configuration>
69+
</plugin>
70+
</plugins>
71+
</build>
72+
<description>The Application front-end designed using JavaFX and Spring Boot is used as backend to bootstrap the app. The scenes are created in FXML using Scene Builder. The app demonstrate simple CRUD using Spring Boot and JavaFX.</description>
73+
</project>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.codetreatise;
2+
3+
import javafx.application.Application;
4+
import javafx.stage.Stage;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
import org.springframework.boot.builder.SpringApplicationBuilder;
7+
import org.springframework.context.ConfigurableApplicationContext;
8+
9+
import com.codetreatise.config.StageManager;
10+
import com.codetreatise.view.FxmlView;
11+
12+
@SpringBootApplication
13+
public class Main extends Application {
14+
15+
protected ConfigurableApplicationContext springContext;
16+
protected StageManager stageManager;
17+
18+
public static void main(final String[] args) {
19+
Application.launch(args);
20+
}
21+
22+
@Override
23+
public void init() throws Exception {
24+
springContext = springBootApplicationContext();
25+
}
26+
27+
@Override
28+
public void start(Stage stage) throws Exception {
29+
stageManager = springContext.getBean(StageManager.class, stage);
30+
displayInitialScene();
31+
}
32+
33+
@Override
34+
public void stop() throws Exception {
35+
springContext.close();
36+
}
37+
38+
/**
39+
* Useful to override this method by sub-classes wishing to change the first
40+
* Scene to be displayed on startup. Example: Functional tests on main
41+
* window.
42+
*/
43+
protected void displayInitialScene() {
44+
stageManager.switchScene(FxmlView.LOGIN);
45+
}
46+
47+
48+
private ConfigurableApplicationContext springBootApplicationContext() {
49+
SpringApplicationBuilder builder = new SpringApplicationBuilder(Main.class);
50+
String[] args = getParameters().getRaw().stream().toArray(String[]::new);
51+
return builder.run(args);
52+
}
53+
54+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
package com.codetreatise.bean;
2+
3+
import java.time.LocalDate;
4+
5+
import javax.persistence.Column;
6+
import javax.persistence.Entity;
7+
import javax.persistence.GeneratedValue;
8+
import javax.persistence.GenerationType;
9+
import javax.persistence.Id;
10+
import javax.persistence.Table;
11+
12+
/**
13+
* @author Ram Alapure
14+
* @since 05-04-2017
15+
*/
16+
17+
@Entity
18+
@Table(name="User")
19+
public class User {
20+
21+
@Id
22+
@GeneratedValue(strategy=GenerationType.IDENTITY)
23+
@Column(name = "id", updatable = false, nullable = false)
24+
private long id;
25+
26+
private String firstName;
27+
28+
private String lastName;
29+
30+
private LocalDate dob;
31+
32+
private String gender;
33+
34+
private String role;
35+
36+
private String email;
37+
38+
private String password;
39+
40+
41+
public long getId() {
42+
return id;
43+
}
44+
45+
public void setId(long id) {
46+
this.id = id;
47+
}
48+
49+
public String getFirstName() {
50+
return firstName;
51+
}
52+
53+
public void setFirstName(String firstName) {
54+
this.firstName = firstName;
55+
}
56+
57+
public String getLastName() {
58+
return lastName;
59+
}
60+
61+
public void setLastName(String lastName) {
62+
this.lastName = lastName;
63+
}
64+
65+
public LocalDate getDob() {
66+
return dob;
67+
}
68+
69+
public void setDob(LocalDate dob) {
70+
this.dob = dob;
71+
}
72+
73+
public String getGender() {
74+
return gender;
75+
}
76+
77+
public void setGender(String gender) {
78+
this.gender = gender;
79+
}
80+
81+
public String getRole() {
82+
return role;
83+
}
84+
85+
public void setRole(String role) {
86+
this.role = role;
87+
}
88+
89+
public String getEmail() {
90+
return email;
91+
}
92+
93+
public void setEmail(String email) {
94+
this.email = email;
95+
}
96+
97+
public String getPassword() {
98+
return password;
99+
}
100+
101+
public void setPassword(String password) {
102+
this.password = password;
103+
}
104+
105+
@Override
106+
public String toString() {
107+
return "User [id=" + id + ", firstName=" + firstName + ", lastName=" + lastName + ", dob=" + dob + ", email="
108+
+ email + "]";
109+
}
110+
111+
112+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package com.codetreatise.config;
7+
8+
import java.io.IOException;
9+
import java.io.StringWriter;
10+
import java.util.ResourceBundle;
11+
import javafx.stage.Stage;
12+
import org.springframework.beans.factory.annotation.Autowired;
13+
import org.springframework.context.annotation.Bean;
14+
import org.springframework.context.annotation.Configuration;
15+
import org.springframework.context.annotation.Lazy;
16+
import org.springframework.context.annotation.Scope;
17+
18+
import com.codetreatise.logging.ExceptionWriter;
19+
20+
@Configuration
21+
public class AppJavaConfig {
22+
23+
@Autowired
24+
SpringFXMLLoader springFXMLLoader;
25+
26+
/**
27+
* Useful when dumping stack trace to a string for logging.
28+
* @return ExceptionWriter contains logging utility methods
29+
*/
30+
@Bean
31+
@Scope("prototype")
32+
public ExceptionWriter exceptionWriter() {
33+
return new ExceptionWriter(new StringWriter());
34+
}
35+
36+
@Bean
37+
public ResourceBundle resourceBundle() {
38+
return ResourceBundle.getBundle("Bundle");
39+
}
40+
41+
@Bean
42+
@Lazy(value = true) //Stage only created after Spring context bootstap
43+
public StageManager stageManager(Stage stage) throws IOException {
44+
return new StageManager(springFXMLLoader, stage);
45+
}
46+
47+
}

0 commit comments

Comments
 (0)