This is a project showcase on how to integrate Springboot JavaFX Client with feathersjs Server, communicate via socketio-client-java. It also uses numerous features from Spring, and applying Spring best practices
The key concept is to demo on how to:
- Create JavaFX client integration with Springboot and Javafx-weaver
- Initialize websocket connection to feathersjs server via socketio-client-java, including auto-reconnection
- Use of
SmartInitializingSingletonto wait until after bean has initialized before performing some actions. SeeWebSocketInitializer - Use of
ApplicationListenereither throughimplementsor@EventListenerto trigger some action, where we can use SpEL to conditional listen to certain event. SeeUserSocketListenerandMainController - Use of
ApplicationEventPublishertopublish(custom) events and@EventListenertosubscribefor events - Use of constructor-injection as DI best practice
- Use of @ConfigurationProperties for typesafe configuration. See
FeathersConfig - Use of configuration-metadata to provide auto-completion in
application.properties - Use of Spring-Security org.springframework.security.core.Authentication to store authenticated user into
SecurityContextHolderand allow to retrieve via@AuthenticatedPrincipalor@CurrentUser - Easily use of POJO object and send through websocket using
ObjectMapperandJSONObject. SeeAuthenticationRequestorUserentity classtoJSONObjectmethod - Use of
spring-boot-starter-data-mongodbto constructQueryobject
The following are yet to be done:
- Use of Transports and HTTP Headers?
- Use of JWT Token for re-authentication after disconnect
- Use of
@Validatedin@ConfigurationProperties - Use of automatic-versioning-of-java-applications-using-git-version-gradle-plugin
- Add support for params in CRUD
- Use native query builder (like mongo-sdk) to write the query, and then output to json which will be sent to server through socket
- Initialize
ObjectMapperwith default prettyprint and timeformat etc - Use of
Converterto convert toJSONObject- See spring-data-custom-converter - Use of
Annotationto auto convertPOJO to JSONObject? https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/reactive/result/method/annotation/PrincipalMethodArgumentResolver.html https://github.com/rwinch/spring-security51-by-example-reactive/blob/master/message/src/main/java/sample/message/CurrentUserIdArgumentResolver.java https://stackoverflow.com/questions/18343129/custom-annotation-binding-in-spring-controller
- Enable
Automatic Project SynchronizationinPreference > Gradle - Add the following to
build.gradlewhich will outputbuild.infoin.jar\BOOT-INF\classes\META-INF\when build
springBoot {
buildInfo()
}
// optionally can add
eclipse {
autoBuildTasks bootBuildInfo
}- No VM args is required (especially for JavaFX) in
Run Configurationsnor is it required after build and run asjar - Google Guava EventBus or Spring-Reactor is an alternative to Spring's
ApplicationEventPublisher - More advance usage of
ApplicationEventPublisherincludes usage of@TransactionalEventListenerand@Async - Can also publish event asynchronously by using
ApplicationEventMulticaster
- Whenever client reconnects, the socket events received will multiply. For example, after reconnection, instead of receiving 1x
onUserCreatedevent, it will receive n times depending on how many times it has reconnected src/main/resources/META-INF/additional-spring-configuration-metadata.jsonhas to be generated viaEclipsemanually to provide auto-completion
- Start server by
cd feathers-server && npm ci && npm run dev - Start client by
cd spring-javafx-client && gradlew clean build bootRun
- does-adding-too-many-application-listeners-affect-performance
- spring-security-programmatic-login-without-a-password
- spring-security-get-password-in-userdetailsservicemethod
- spring-security-jwt-validation-without-using-usernamepasswordauthenticationtoken
- springboot-gradle-plugin-not-working-with-eclipse
- jackson-builder-pattern
- javafx-getting-started
- creating-a-spring-boot-javafx-application-with-fxweaver/
- run-initialization-code-spring-boot
- spring-boot-application-events-explained
- Spring Boot @ConfigurationProperties Tips & Tricks
- publishing-events-asynchronously
- custom-events-and-generic-events-in-spring
- spring-event-event-driven
- inter-bean-notifications-using-spring-events
- Jacksonized
- flexible-immutability-with-jackson-and-lombok/