I am developing pathology lab management desktop app in Javafx and wanted to use JPA from spring project. Actually it will be spring application with Javafx and JPA. So I wanted to ask if i can call rest end points in desktop application.
Asked
Active
Viewed 1,226 times
0
-
1Yes, you can use [spring webclient](https://www.baeldung.com/spring-5-webclient) or other technologies to call a rest service from JavaFX. webclient is async so calls won't block the JavaFX thread, just make sure you use Platform.runLater if you update the UI in response handling. – jewelsea Mar 13 '22 at 12:11
-
It is unclear from your question where the JPA and Spring is. For example, if you have non-Spring JavaFX client and a separate Spring server with JPA providing a rest API for access, OR if you have JavaFX app which runs on Spring and accesses a database via JPA (in which case I don't know why you would have rest as well). – jewelsea Mar 13 '22 at 12:14
-
the reason i wanted to use rest was to free myself from monolithic application. I wanted to decouple each service and then call it from javafx client. – khizar khan Mar 13 '22 at 12:18
-
@jewelsea "if you have JavaFX app which runs on Spring and accesses a database via JPA" ok how can I do this – khizar khan Mar 13 '22 at 12:25
-
1[SpringBoot + JavaFX](https://stackoverflow.com/questions/57887944/adding-spring-dependency-injection-in-javafx-jpa-repo-service) [SpringData + JavaFX](https://stackoverflow.com/questions/61274423/spring-data-jpa-with-java-fx). This is not an easy task. Tutorials on JavaFX are at Oracle. Tutorials on Spring are at Baeldung. Tutorials on mixing the two technologies can be found but are very sketchy. Be prepared to do a lot of work with little assistance. – jewelsea Mar 13 '22 at 12:37
-
@Jewelsea ok thanks. – khizar khan Mar 13 '22 at 13:08
1 Answers
0
I assume you have a (spring) rest server and a java(fx) client. In the client you could go something like this:
...
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.core.Response;
import java.net.URI;
...
class <your class>
{
Client client;
...
void <your method>
{
...
client = ClientBuilder.newClient();
...
URI uri = URI.create(<your rest server uri>);
Response response = client.target(uri).request().get();
<your_java_type> entity = response.readEntity(<your_java_type>.class);
...
}
...
}
Is that what you are looking for?

r-uu
- 423
- 1
- 4
- 18