J-Framework Service
J-Framework Service helps to start developing microservices in Java in no time, with zero-config.
Dependency
Most likely, you will NOT need to add the direct dependency of this project, since it’s already included in the parent projects or the other framework projects. However, if you need to, the dependency is added as follows.
<!-- https://mvnrepository.com/artifact/com.jalalkiswani/j-framework-core -->
<dependency>
<groupId>com.jalalkiswani</groupId>
<artifactId>j-framework-service</artifactId>
<version>7.0.0-SNAPSHOT</version>
</dependency>
Basic Usage
-
Your REST controllers should extend
JKAbstractRestController
, for example:
package com.app.person;
import com.jk.services.server.JKAbstractRestController;
import jakarta.ws.rs.*;
@Path("/example")
public class Controller extends JKAbstractRestController{
@GET
@Path("hello")
public String sayHello() {
return "Hello from uncle Jalal";
}
@GET
@Path("/hello/{name}")
public String sayHelloWithPathParam(@PathParam(value = "name") String name) {
return "Hello, " + name;
}
@POST
@Path("/hello")
//The Model class should contains name and age instance variables with setters and getters
public String sayHelloWithBody(Model p) {
return "Hello, " + p.getName() + ", your age is: " + p.getAge();
}
}
-
Create an
App
class that should contain@ApplicationPath("app")
annotation, and extendJKServiceConfig
, for example:
package com.app;
import com.jk.services.server.JKServiceConfig;
import com.jk.web.embedded.JKWebApplication;
import jakarta.ws.rs.ApplicationPath;
@ApplicationPath("app")
public class App extends JKServiceConfig{
/**
*
* @param args
*/
public static void main(String[] args) {
JKWebApplication.run(8080,false);
}
}
Benefits
Using J-Framework-Service, you will get many benefits, the following are some of them:
-
All dependencies and configurations needed to develop Jakarta EE 10 microservices using Java.
-
Context synchronization filters
-
Default Exception Handler that publishes exceptions to the configured
Unified Logging Service
. -
Tuned proper configurations to Jersey and JSON handlers.
-
Set of utility services such as:
-
Info Service: available at
/util/info
URL, which shows all the currently available controllers and endpoints details. -
Config Service: available at
/util/config
URL, which allows reloading config and the retrieval of (password masked) configuration. -
Header Service: available at
/util/headers
URL, which allows to show clients header sent to server, useful for debugging purposes. -
Log Service: available at
/util/log
URL, which shows [password masked] server logs. -
Ping Service: available at
/util/ping
URL. -
Hi Service: available at
/util/hi
URL.
-
All critical endpoints are disabled by default, check the Configurations section for more information. Also, be sure to set |
Configurations
For the list of available configurations of the Service project, check the Configuration Section.