Entradas

Spring Boot (3) Selecting the service dynamically

 1. Defining the services implementing an interface The aim is to get a service dynamically by its class name. First, a simple interface is defined (IProcess.java) package websocket . services ; import java . util . Map ; import org . springframework . messaging . simp . SimpMessageSendingOperations ; public interface IProcess { public boolean execute ( SimpMessageSendingOperations messagingTemplate , String subscription , Map < String , Object > map ) ; } Let's create some services implementing this interface (but only one is shown) for instance Process01 package websocket . services ; import java . util . Map ; import org . springframework . messaging . simp . SimpMessageSendingOperations ; import org . springframework . stereotype . Service ; @Service("Proces01") public class Process01 implements IProcess { @Override public boolean execute ( SimpMessageSendingOperations messagingTemplate , String subscription ...

Spring Boot (2) Websockets. Subscriptions of only one member

Imagen
 1. Introduction WebSockets are useful for informing a user of the progress of a heavy process. There are a lot of blogs and videos about this question.  Spring boot uses the STOMP protocol 2. Creating the project Use Spring boot initializer  for creating the project, use these dependencies: Spring boot dev tools Lombok Spring Web Thymeleaf Websocket And use gradle format Then import it from Eclipse as File > Import > Gradle > Existing Gradle Project The final project structure after adding all the needed classes, html and js file is: 3. Add the needed dependencies to the build.gradle file Add javascript dependencies to the build.gradle implementation ' org.webjars:webjars-locator-core ' implementation ' org.webjars:sockjs-client:1.5.1 ' implementation ' org.webjars:stomp-websocket:2.3.4 ' implementation ' org.webjars:bootstrap:3.3.7 ' implementation ' org.webjars:jquery:3.6.4 ' Add also the Gson dependencies, and the build.xml file ...

Spring Boot (1) Creating an application

Imagen
1. Creating a project 1. Download IntelliJ or Eclipse 2. Use Initializr to create a gradle project. An example of creating an application is: 3. Import from IntelliJ Extrat the zip file. File -> New -> Project from existing sources and select the build.gradle file  The Project, editor and gradle windows are displayed. If we try to run the application (Gradle window ->demo02 -> Tasks -> application -> bootRun) fails "application finished with non-zero exit value 1" 2- Review of web and REST concepts URL concepts REST API Methods From testfully.io : GET               Retrieves information POST            Creates a respource PUT                Updates enterely a resource PATCH         Updates partiall a resource DELETE      Deletes a resource HEAD           Similar to GET but has no BODY response...