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

  • SAP HANA Database SAP HANA is an in-memory, column-oriented, relational database management system developed and marketed by SAP SE. Its primary function as database server is to store and retrieve data as requested by the applications. In addition, it performs advanced analytics (predictive analytics, spatial data processing, text analytics, text search, streaming analytics, graph data processing) and includes ETL capabilities as well as an application server.
  • Try CloudFoundry Try CloudFoundry
  • Microservices - Restful API Spring Restful Representational state transfer (REST) or RESTful web services is a way of providing interoperability between computer systems on the Internet. REST-compliant Web services allow requesting systems to access and manipulate textual representations of Web resources using a uniform and predefined set of stateless operations. Other forms of Web service exist, which expose their own arbitrary sets of operations such as WSDL and SOAP.
  • Maven Best Practices Maven Best Practices
  • Cloud Training 1 - Create Maven Project and Deploy to Tomcat
  • Unit Test by Spring MVC Test Framework Testing is an integral part of enterprise software development. Dependency Injection should make your code less dependent on the container than it would be with traditional Java EE development. This topic introduce how to create Unit Test by Spring MVC Test Framework for Java project on HCP

Comments

comments powered by Disqus
Back to Top