How to interact with client only Spring Boot application - java

Circumstances
I have a spring boot application that is not accessible via web (spring.main.web-environment=false). The purpose of using spring boot is to have an out of the box support for interacting with a database. Maybe a JPA layer alone would also have been sufficient, but I went for spring boot.
The program has a GUI (JavaFX), and this GUI interacts with the spring boot application whenever a DB interaction is necessary.
Question
Now I am a bit confused, how the GUI can interact with Spring Boot. I start Spring Boot, better to say the main application (#SpringBootApplication) at the startup of the program (in a Thread if that matters, as it must not block the GUI). So far so good. But how can I call methods in spring boot? My last project was a web project, and I used REST APIs with according Spring Boot Controllers, which allowed me to interact with Spring Boot via a e.g. a browser.
But now I am client only, and I want to call methods which do something within my Spring boot Application from the GUI, e.g. when a button is pressed.
Maybe this is answered easily, but I couldn't find how to do it properly. I built a solution with ApplicationRunner where every time a new spring boot application is started and closed after doing it's job, but this is not really elegant, and I am not able to retrieve parameters back with this technique.

Related

Integrating Hibernate to Spring running on embedded jetty

I have just returned to Spring after 5 years of gap and it seems lot is changed. I have a task to create a REST Service using Spring with hibernate as an ORM, So far I am able to run a basic Rest Service using embedded jetty and able to make GET/POST calls, the next is to integrate hibernate into it so that the data fetch/Sent operation actually use MySQL instead of sending hard-coded response(which I have done currently).
The issue is earlier I used to work on Spring MVC using Tomcat where we had web.xml to define the dispatcher servlet and application-context which in turn were used to define hibernate config and other beans declaration, but now having embedded jetty I am not finding a way to integrate hibernate to my REST app, Is the way to add configuration is changed from XML to class based config. I searched over internet but maybe I am out of words or not using correct keywords, in short, Have no luck finding some solution to integrate hibernate to my Spring app which is using embedded jetty.
Could some please breif me about the recent changes or point me to the right tutorial ?
Any help appreciated, thanks in advance !
ps - I have used this example to progress so far https://github.com/pethoalpar/SpringMvcJettyExample
Yes , lot of changes in these 5 years and one of the game-changer is spring-boot
If you want to build a brand new project especially if you want to run the web application on the embedded container such as Jetty , you can check out spring-boot.It already provides integration with Jetty , hibernate and Spring MVC REST service.
The end result is that you just need to change a little bit configuration (most probably the DB connection info) and you can quickly get a production-ready REST service backed by JPA/Hibernate which can just run without any XML configuration anymore.
There are tons of tutorials in Internet talking about how to do it . You should easily find them out such as this using the keywords something likes "springboot webservice hibernate jetty" etc.

Can I run long tasks in a Spring Boot application?

I have a Spring Boot application, which shows some data from MongoDB on an AngularJS page and allows the user to change it.
Now I need to create a mechanism, which allows me to
run a long (1-3 hours) Java method,
which produces some files and
observe its state via web (does it run, is it finished, did it crash?).
Can I implement this in scope of the Spring Boot application? If yes, what parts of Spring can I use to do that?
I would argue that it's not good idea to embed batch processing into your service exposing MongoDB data store.
I would create separate batch application. Spring Batch would be natural choice if you are using Spring stack. You would need to figure out how you want to host Spring Batch job and how you want to trigger and schedule it. Spring Batch needs SQL storage for it's metadata.
Status of the batch processing could be monitored by one other application with Spring Batch Admin module running on Servlet container. If you point this application to SQL storage of Spring Batch job application, you get monitoring of status via web UI out of the box.
Of course it could run each app with Spring Boot.
If you don't want to handle this operational complexity it brings to host there three applications, yous still can all three embed into one and it would work fine with Spring Boot. You could even execute jobs with parameters manually or restart them via Spring Batch Admin configured to have access to Spring Batch Job beans.
You could also explore using MongoDb as storage for Spring Batch metadata. E.g. this project may help. But such mechanism would need to be used by Spring Batch application and also by Spring Batch Admin module visualizing status of processing.

Is it possible to add spring MVC (with embedded Jetty) to a spring integration component

I have examples of both working individually, now trying to merge so that I have both capabilities / entry points.
Not surpised it is confused about the application contexts to load.
I want to know if this is even possible and if so any examples?
I know it is doable with spring boot however not wanting to move to that just yet.
I am attempting the impossible?
"Spring MVC (with embedded Jetty)" usually means an HTTP endpoint running in its own JVM (I suppose you have a main method that starts Jetty). Once you have that started, you can integrate it as any other HTTP endpoint in Spring Integration.
If you want them both to run in the same JVM, that probably means you don't want to make use of HTTP as you can invoke methods directly on your #Controllers or #Services.
Or perhaps I'm missing something here... ?
I'd go for Spring Boot. Version 1.1.6 was just released. I'm currently also migrating an "old" SI application to be based upon Spring Boot. I suggest you give http://start.spring.io a try. Migration should not be too difficult.

Does Spring Boot support servlet 2.5 auto-configuration?

I would like to create a Spring Boot application to be deployed on Google AppEngine infrastructure. GAE currently only supports servlet 2.5 web applications.
Is it possible to use Spring Boot - using auto-configuration - in combination with a old-fashioned web.xml?
Can I for example use a contextClass/contextConfigLocation pointing to a #Configration class including #EnableAutoConfiguration?
All Spring Boot examples seem to use a simple Application class with main method to run the application. So I would like to know if Spring Boot supports using a web.xml as start point to boot the application?
More than one question there:
There's nothing stopping you from using web.xml (it's still part of the Servlet spec). Most people prefer the Java initializers these days.
#EnableAutoConfiguration works for any application context (it just uses features of Spring).
But Spring Boot out of the box doesn't have a ContextLoaderListener that knows about SpringApplication, so you miss some of the benefits of Boot if you do as you describe. There's one you might find useful here.
Spring Boot Actuator relies on a few Servlet 3.0 features here and there so you need workarounds for a 2.5 environment (see this spring-boot-legacy prototype for details).
There's a sample app here that runs on GAE, currently deployed here: http://dsyerboot.appspot.com/.

Liferay spring integration

I try to use Spring to develop liferay portlets (version 6.0.6), could i use models and services generated by ServiceBuilder as spring bean?
I tried to import generated spring context in my own, but i got many errors in tomcat log. Maybe the best way is creation of own layer model and services using hibernate for example?
I would recommend that you go ahead and create your own service and persistence classes. Those have nothing to do with UI, so you can use them whether you plunge ahead with portal or not.
If you're using Spring already, and you're planning to move on to portal, you should be thinking about Spring portal. Now it's just the same as Spring web MVC, just with different controllers.

Categories

Resources