From 65111a4666734f77d9b5ad8d1b20ac41e8766006 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 31 Oct 2017 18:23:31 +0200 Subject: [PATCH] spring-rest-shell (#2928) * code snippets for the `Java 9 Stream API improvements` article * code snippets for the `Java 9 Stream API improvements` article [2 attempt] * removed the first attempt * the Spring 5 WebClient * delted stream features test * HttpMediaTypeNotAcceptableExceptionExampleController [0] * reactive web client service was removed * new WebClient * new WebClient [2] * spring-rest-shell init * pom added * readme added --- .../reactive/client/WebClientController.java | 3 +- spring-rest-shell/README.md | 5 ++ spring-rest-shell/pom.xml | 60 +++++++++++++++++++ .../main/java/com/baeldung/Application.java | 13 ++++ .../java/com/baeldung/acticle/Article.java | 40 +++++++++++++ .../baeldung/acticle/ArticleRepository.java | 18 ++++++ 6 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 spring-rest-shell/README.md create mode 100644 spring-rest-shell/pom.xml create mode 100644 spring-rest-shell/src/main/java/com/baeldung/Application.java create mode 100644 spring-rest-shell/src/main/java/com/baeldung/acticle/Article.java create mode 100644 spring-rest-shell/src/main/java/com/baeldung/acticle/ArticleRepository.java diff --git a/spring-5/src/main/java/com/baeldung/web/reactive/client/WebClientController.java b/spring-5/src/main/java/com/baeldung/web/reactive/client/WebClientController.java index 7bab288bab..a218c6b7cf 100644 --- a/spring-5/src/main/java/com/baeldung/web/reactive/client/WebClientController.java +++ b/spring-5/src/main/java/com/baeldung/web/reactive/client/WebClientController.java @@ -43,7 +43,8 @@ public class WebClientController { WebClient.RequestHeadersSpec requestSpec2 = uri2.body(BodyInserters.fromObject("data")); // inserters - BodyInserter, ReactiveHttpOutputMessage> inserter1 = BodyInserters.fromPublisher(Subscriber::onComplete, String.class); + BodyInserter, ReactiveHttpOutputMessage> inserter1 = BodyInserters + .fromPublisher(Subscriber::onComplete, String.class); LinkedMultiValueMap map = new LinkedMultiValueMap<>(); map.add("key1", "value1"); diff --git a/spring-rest-shell/README.md b/spring-rest-shell/README.md new file mode 100644 index 0000000000..06e18450c6 --- /dev/null +++ b/spring-rest-shell/README.md @@ -0,0 +1,5 @@ +## Spring REST Shell Project + +### Relevant Articles + +- [Spring REST Shell](http://www.baeldung.com/) \ No newline at end of file diff --git a/spring-rest-shell/pom.xml b/spring-rest-shell/pom.xml new file mode 100644 index 0000000000..fe255b397f --- /dev/null +++ b/spring-rest-shell/pom.xml @@ -0,0 +1,60 @@ + + + 4.0.0 + + com.baeldung + spring-rest-shell + 0.0.1-SNAPSHOT + jar + + spring-rest-shell + A simple project to demonstrate Spring REST Shell features. + + + org.springframework.boot + spring-boot-starter-parent + 1.5.8.RELEASE + + + + + UTF-8 + UTF-8 + 1.8 + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-data-rest + + + + + com.h2database + h2 + runtime + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + diff --git a/spring-rest-shell/src/main/java/com/baeldung/Application.java b/spring-rest-shell/src/main/java/com/baeldung/Application.java new file mode 100644 index 0000000000..37dbe7dab8 --- /dev/null +++ b/spring-rest-shell/src/main/java/com/baeldung/Application.java @@ -0,0 +1,13 @@ +package com.baeldung; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} diff --git a/spring-rest-shell/src/main/java/com/baeldung/acticle/Article.java b/spring-rest-shell/src/main/java/com/baeldung/acticle/Article.java new file mode 100644 index 0000000000..6a55517f9f --- /dev/null +++ b/spring-rest-shell/src/main/java/com/baeldung/acticle/Article.java @@ -0,0 +1,40 @@ +package com.baeldung.acticle; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +@Entity +public final class Article { + + @Id + @GeneratedValue + private Long id; + private String title; + private String content; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + +} diff --git a/spring-rest-shell/src/main/java/com/baeldung/acticle/ArticleRepository.java b/spring-rest-shell/src/main/java/com/baeldung/acticle/ArticleRepository.java new file mode 100644 index 0000000000..83daf819f0 --- /dev/null +++ b/spring-rest-shell/src/main/java/com/baeldung/acticle/ArticleRepository.java @@ -0,0 +1,18 @@ +package com.baeldung.acticle; + +import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.query.Param; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; + +import java.util.Optional; + +@RepositoryRestResource( + path = "articles", + collectionResourceRel = "articles", + itemResourceRel = "article" +) +public interface ArticleRepository extends CrudRepository { + + Optional
findByTitle(@Param("title") String title); + +}