Spring Boot
In this section you will learn how to install
KSearch library in a Spring Boot project.
Previous requirements
- Have a Spring Boot project in which you want to install
KSearch. - Have JPA installed via the spring-boot-starter-data-jpa dependency.
Step 1: Install K-Spring dependency via Maven
Copy the K-Spring dependency in your pom.xml file, then, force to your project to download dependency.
<dependency> <groupId>com.myzlab</groupId> <artifactId>K-Spring</artifactId> <version>1.1.38</version></dependency>Step 2: Tell
KSearch where the entity manager is
To do this, create a class K that inherits from ve.zlab.k.KSearch and implements ve.zlab.k.KExecutor.
Assuming that the root package of your project is com.example, then you must to create the package com.example.k and the new class would be located there.
package com.example.k;import javax.persistence.EntityManager;import javax.persistence.PersistenceContext;import org.springframework.stereotype.Component;import ve.zlab.k.KExecutor;import ve.zlab.k.KSearch;@Component //Don't forget it!public class K extends KSearch implements KExecutor { @PersistenceContext private EntityManager entityManager; @Override public EntityManager getEntityManager() { return entityManager; }}Ready to use!
With these single steps, you will be able to use the KExecutor object via dependency injection. This object will allow you to access all the functionalities that
KSearch has for you.
To inject the KExecutor object, simply declare this object as an attribute and then add the @Autowired tag as follows:
import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Repository;import ve.zlab.k.KExecutor;@Repositorypublic class MyClass { @Autowired private KExecutor k; public void readyToUse() { k. // Use me! }}What's next?
If this is your first time using
KSearch, please read our recommendations in the next section.
If this is not your case, go ahead and read about the SQL statement you need.