Restful Web services with Spring boot Simple Example

Restful Web services with Spring boot Simple Example This post is aimed to give understanding about web service with spring (through spring boot) for beginners.   Steps to Create a simple restful web service: 1. Create a normal class and add @RestController annotation. @RestController public class GreetingController{ }   2. Create a method and add @RequestMapping(“/greeting”) annotation. Here /greeting refers

198 total views, 0 views today

» Read more

Reading ClassPath file in Spring Boot/Core Example

This below program reads the status.txt file from the classpath, that is src/main/resources in the maven projects using classpathloader in spring core/spring boot projects. Classpathloader converts it to inputstream, from inputstream we can convert to bufferedinputstream and read the file contents easily. File Structure: Here we have status.txt file inside the resources folder, and we have only the value 100

180 total views, no views today

» Read more

Scheduler in Spring Boot with 3 Simple Steps Example

Scheduler in Spring Boot with 3 Simple Steps Example: Scheduler in spring boot became very simple and any one create a Cron job or scheduler in spring boot with just 3 steps. Step 1: Enable spring boot for schedules Add @EnableScheduling to your spring boot main class. @SpringBootApplication @EnableScheduling public class SpringBootStarter{ public static void main(String[] args) { SpringApplication.run(SpringBootStarter.class, args); }

299 total views, 0 views today

» Read more

Spring Boot + EhCache Hibernate Working Example

Spring Boot + Ehcache Hibernate Working Example: When I was trying to populate JSON records in my angular app (just 1885 records only), it took around 11 seconds and in angular side I am just populating in the datatable. So I thought to implement ehcache with spring boot to make it faster. After implementing that successfully I am really surprised

379 total views, no views today

» Read more

Join two tables using Hibernate in Spring Boot Example

Join two tables using Hibernate in Spring Boot Example: Many enterprise applications whichever using hibernate uses sql queries only for joins still and uses hibernate only for save/update operations. Today we are going to see how to use hibernate to join two tables. We are going to see how to get count(*) using hibernate along with group by function in

417 total views, 0 views today

» Read more

Spring Boot Native Query Example

Spring Boot Native Query Example: In Spring boot, database operations can be performed by implementing CrudRepository<Object, Long> in our @Repository interface. Here¬†Object is our entity class. @Query Annotation: We can execute nativeQueries using @Query annotation. Need to make the nativeQuery boolean to true and provide the native query to value parameter for @Query annotation.   Syntax: @Query(nativeQuery=true, value=”select s.store_name, s.store_url

333 total views, 0 views today

» Read more

Spring Boot with CriteriaBuilder for Dynamic Search Queries

Spring Boot with CriteriaBuilder for Dynamic Search Queries: Spring Boot with CriteriaBuilder for Dynamic Search Queries: When you are developing an enterprise application, you have to provide a search option dynamically with “and” condition. Our grand father way to do is using stringbuilder to construct the query in java and return the result. But hibernate has provided criteria for the

388 total views, no views today

» Read more

[Solved] The type CriteriaQuery is not generic;

[Solved] The type CriteriaQuery is not generic; It is because of the incorrect import. CriteriaQuery is available in both hibernate and persistence package. We have to import from persistence package in order to use criteriabuilder. CriteriaQuery should be imported from import javax.persistence.criteria.CriteriaQuery;   not from import org.hibernate.criterion.CriteriaQuery;   Sample snippet: @PersistenceContextprivate EntityManager em; CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<AffiliateUrl> cq =

288 total views, no views today

» Read more

Angular 4 + Spring Boot CRUD Example

Angular 4 + Spring Boot CRUD ExampleAngular 4 + Spring Boot CRUD Example Angular 4 through Angular-CLI(command line interface) is becoming popular and with spring boot lot of projects started fresh developments and started their migrations to these technologies. What are we going to achieve: 1. Angular 4 UI 2. Spring boot rest API 3. CRUD(Create,read,update,delete) Operations. Requirements: 1. NPM

561 total views, 0 views today

» Read more

Difference between @Controller and @RestController

Difference between @Controller and @RestController: @Controller and @RestController is not having much difference, its just a matter of convenience to use @ResponseBody with @Controller. In simple way, we can understand like this: @RestController = @Controller + @ResponseBody     @Controller: @ResponseBody annotation should be used for RequestMapping methods to render any outputs like json/xml etc.   Code Sample: Here @ResponseBody

479 total views, 0 views today

» Read more
1 2