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
SmartInitializingSingleton
to wait until after bean has initialized before performing some actions. SeeWebSocketInitializer
- Use of
ApplicationListener
either throughimplements
or@EventListener
to trigger some action, where we can use SpEL to conditional listen to certain event. SeeUserSocketListener
andMainController
- Use of
ApplicationEventPublisher
topublish
(custom) events and@EventListener
tosubscribe
for 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
SecurityContextHolder
and allow to retrieve via@AuthenticatedPrincipal
or@CurrentUser
- Easily use of POJO object and send through websocket using
ObjectMapper
andJSONObject
. SeeAuthenticationRequest
orUser
entity classtoJSONObject
method - Use of
spring-boot-starter-data-mongodb
to constructQuery
object
The following are yet to be done:
- Use of Transports and HTTP Headers?
- Use of JWT Token for re-authentication after disconnect
- Use of
@Validated
in@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
ObjectMapper
with default prettyprint and timeformat etc - Use of
Converter
to convert toJSONObject
- See spring-data-custom-converter - Use of
Annotation
to 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 Synchronization
inPreference > Gradle
- Add the following to
build.gradle
which will outputbuild.info
in.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 Configurations
nor 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
ApplicationEventPublisher
includes usage of@TransactionalEventListener
and@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
onUserCreated
event, it will receive n times depending on how many times it has reconnected src/main/resources/META-INF/additional-spring-configuration-metadata.json
has to be generated viaEclipse
manually 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/