Tiven Wang
Wang Tiven February 23, 2017
425 favorite favorites
bookmark bookmark
share share

The project codes for this article can be downloaded from Github.

Spring helps development teams everywhere build simple, portable, fast and flexible JVM-based systems and applications. Spring has a lot of projects for whatever the infrastructure needs of your application may be, from configuration to security, web apps to big data, there is a Spring Project to help you build it. Start small and use just what you need.

We used Spring projects:

  • Spring Data JPA: The goal of Spring Data repository abstraction is to significantly reduce the amount of boilerplate code required to implement data access layers for various persistence stores.
  • Spring Data Rest: Spring Data REST builds on top of Spring Data repositories and automatically exports those as REST resources. It leverages hypermedia to allow clients to find functionality exposed by the repositories and integrates these resources into related hypermedia based functionality automatically.
  • Spring Data RestDocs: The aim of Spring REST Docs is to help you to produce documentation for your RESTful services that is accurate and readable.

Spring Data JPA

Add Dependencies

<dependency>
  <groupId>org.springframework.data</groupId>
  <artifactId>spring-data-jpa</artifactId>
  <version>1.9.4.RELEASE</version>
</dependency>

Spring Configuration

The configuration set up Spring to create proxy instances for those interfaces:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:jpa="http://www.springframework.org/schema/data/jpa"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
     http://www.springframework.org/schema/beans/spring-beans.xsd
     http://www.springframework.org/schema/data/jpa
     http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">
  ...
  <jpa:repositories base-package="com.sap.c4c.wechat.repository"/>
  ...
</beans>

Declare Repository

package com.sap.c4c.wechat.repository;

import java.util.List;

import org.springframework.data.repository.CrudRepository;
import com.sap.c4c.wechat.model.Message;

public interface MessageRepository extends CrudRepository<Message, Long> {
	List<Message> findByType(String type);
}

Similar Posts

Comments

Back to Top