fbpx

Spring 5 integration

Find out how to integrate JSQL with Spring 5

Stack requirements

The JSQL Spring 5 library will not work without an account in the JSQL cloud and a backend application written in Spring 5. To learn more see overview.

Spring 4 compatibility

The JSQL plugin for Spring 5 should work for Spring 4 without any problems, however, we do not provide official support for this version of the framework.

Installation

Add JSQL artifactory into your maven repositories in your project.

For Maven setup:

<repositories>
<repository>
<id>maven</id>
<url>https://nexus.jsql.it/nexus/content/repositories/releases/</url>
</repository>
</repositories>

For Gradle setup:

repositories {

    mavenCentral()
    maven{
        url "https://nexus.jsql.it/nexus/content/repositories/releases/"
    }

}

Then add jsql-spring-plugin dependency:

Releases list

For Maven setup:

<dependency>
<groupId>jsql</groupId>
<artifactId>spring-plugin</artifactId>
<version>1.5.7</version>
<type>pom</type>
</dependency>

For Gradle setup:

compile "jsql:spring-plugin:1.5.7"

Integration

The JSQL plugin for Spring 5 has the same integration principle as the Java EE or Spring Boot plugin. All you need to do is create a controller that will inherit from JSQLController and override getConfig method.

Example REST controller inheriting JSQLController:

import it.jsql.connector.controller.JSQLController;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ExampleController extends JSQLController {

}

Now we have to implement the getJsqlService method and return the JSQLService instance from it:

@Override
public JSQLConfig getConfig() {
return new JSQLConfig("YOUR_API_KEY", "YOUR_PRODUCTION_KEY");
}

The API_KEY and DEV_KEY we can get from JSQL Admin Panel, see FAQ for details.

We can save them as protected final fields or store in file:

protected final String API_KEY = "==iSqF8rKvVeSgqudKDOXpjiFgGMJh1PbeouIz9IW/YQ==9CI8ox66gogpoSXm6yr";
protected final String DEV_KEY = "Z6kEovODxAv2I5hKekMyUw==";

Let’s show whole REST controller class implementation:

import it.jsql.connector.controller.JSQLController;
import it.jsql.connector.dto.JSQLConfig;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ExampleController extends JSQLController {

 protected final String API_KEY = "==iSqF8rKvVeSgqudKDOXpjiFgGMJ1PbeouIzIW/YQ==9CI8ox66gogpoSXm6yr";
 protected final String DEV_KEY = "Z6kEovOiAv2I5hKekMyUw==";

 @Override
public JSQLConfig getConfig() {
return new JSQLConfig(API_KEY, DEV_KEY);
} }

Usage

If your application is integrated using the JSQL plugin, you can start it and try to call the query using CURL:

curl 'http://localhost:8080/api/jsql/select' -H 'Accept: application/json' -H 'Content-Type: application/json' 
--data-binary '{"token":"msd90sm2msdaid873423b4qw0dp3m","params":{}}' --compressed

What next?

Close Menu