Skip to content

Commit 66449db

Browse files
committed
spring cloud rest initial commit
1 parent 4c437b5 commit 66449db

15 files changed

Lines changed: 453 additions & 0 deletions

File tree

‎spring-cloud/pom.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<module>spring-cloud-hystrix</module>
1313
<module>spring-cloud-bootstrap</module>
1414
<module>spring-cloud-ribbon-client</module>
15+
<module>spring-cloud-rest</module>
1516
</modules>
1617
<packaging>pom</packaging>
1718

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
4+
### STS ###
5+
.apt_generated
6+
.classpath
7+
.factorypath
8+
.project
9+
.settings
10+
.springBeans
11+
12+
### IntelliJ IDEA ###
13+
.idea
14+
*.iws
15+
*.iml
16+
*.ipr
17+
18+
### NetBeans ###
19+
nbproject/private/
20+
build/
21+
nbbuild/
22+
dist/
23+
nbdist/
24+
.nb-gradle/
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>org.baeldung</groupId>
7+
<artifactId>spring-cloud-rest</artifactId>
8+
<version>1.0.0-SNAPSHOT</version>
9+
<modules>
10+
<module>spring-cloud-rest-server</module>
11+
<module>spring-cloud-rest-client</module>
12+
</modules>
13+
<packaging>pom</packaging>
14+
15+
<name>spring-cloud-rest</name>
16+
17+
<properties>
18+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
19+
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
20+
<spring-boot-maven-plugin.version>1.4.2.RELEASE</spring-boot-maven-plugin.version>
21+
</properties>
22+
23+
<build>
24+
<pluginManagement>
25+
<plugins>
26+
<plugin>
27+
<groupId>org.apache.maven.plugins</groupId>
28+
<artifactId>maven-compiler-plugin</artifactId>
29+
<version>${maven-compiler-plugin.version}</version>
30+
<configuration>
31+
<source>1.8</source>
32+
<target>1.8</target>
33+
</configuration>
34+
</plugin>
35+
<plugin>
36+
<groupId>org.springframework.boot</groupId>
37+
<artifactId>spring-boot-maven-plugin</artifactId>
38+
<version>${spring-boot-maven-plugin.version}</version>
39+
</plugin>
40+
</plugins>
41+
</pluginManagement>
42+
</build>
43+
</project>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>org.baeldung</groupId>
7+
<artifactId>spring-cloud-rest-client</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
11+
<name>spring-cloud-rest</name>
12+
<description>Demo project for Spring Boot</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.4.3.RELEASE</version>
18+
<relativePath/> <!-- lookup parent from repository -->
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24+
<java.version>1.8</java.version>
25+
</properties>
26+
27+
<dependencies>
28+
<dependency>
29+
<groupId>org.springframework.cloud</groupId>
30+
<artifactId>spring-cloud-starter-eureka</artifactId>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.springframework.boot</groupId>
34+
<artifactId>spring-boot-starter-data-jpa</artifactId>
35+
</dependency>
36+
<dependency>
37+
<groupId>com.h2database</groupId>
38+
<artifactId>h2</artifactId>
39+
</dependency>
40+
<dependency>
41+
<groupId>org.springframework.boot</groupId>
42+
<artifactId>spring-boot-starter-web</artifactId>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.springframework.boot</groupId>
46+
<artifactId>spring-boot-starter-data-rest</artifactId>
47+
</dependency>
48+
49+
<dependency>
50+
<groupId>org.springframework.boot</groupId>
51+
<artifactId>spring-boot-starter-test</artifactId>
52+
<scope>test</scope>
53+
</dependency>
54+
</dependencies>
55+
56+
<dependencyManagement>
57+
<dependencies>
58+
<dependency>
59+
<groupId>org.springframework.cloud</groupId>
60+
<artifactId>spring-cloud-dependencies</artifactId>
61+
<version>Camden.SR4</version>
62+
<type>pom</type>
63+
<scope>import</scope>
64+
</dependency>
65+
</dependencies>
66+
</dependencyManagement>
67+
68+
<build>
69+
<plugins>
70+
<plugin>
71+
<groupId>org.springframework.boot</groupId>
72+
<artifactId>spring-boot-maven-plugin</artifactId>
73+
</plugin>
74+
</plugins>
75+
</build>
76+
77+
78+
</project>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.baeldung;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
6+
7+
@SpringBootApplication
8+
@EnableEurekaClient
9+
public class SpringCloudRestClientApplication {
10+
11+
public static void main(String[] args) {
12+
SpringApplication.run(SpringCloudRestClientApplication.class, args);
13+
}
14+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.baeldung.persistence.dao;
2+
3+
import org.baeldung.persistence.model.Book;
4+
import org.springframework.data.jpa.repository.JpaRepository;
5+
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
6+
7+
@RepositoryRestResource(collectionResourceRel = "books", path = "books")
8+
public interface BookRepository extends JpaRepository<Book, Long> {
9+
10+
}
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
package org.baeldung.persistence.model;
2+
3+
import javax.persistence.Column;
4+
import javax.persistence.Entity;
5+
import javax.persistence.GeneratedValue;
6+
import javax.persistence.GenerationType;
7+
import javax.persistence.Id;
8+
9+
@Entity
10+
public class Book {
11+
@Id
12+
@GeneratedValue(strategy = GenerationType.AUTO)
13+
private long id;
14+
15+
@Column(nullable = false)
16+
private String title;
17+
18+
@Column(nullable = false)
19+
private String isbn;
20+
21+
@Column(nullable = false)
22+
private String author;
23+
24+
//
25+
26+
public Book() {
27+
super();
28+
}
29+
30+
public Book(String title, String isbn, String author) {
31+
super();
32+
this.title = title;
33+
this.isbn = isbn;
34+
this.author = author;
35+
}
36+
37+
//
38+
39+
public long getId() {
40+
return id;
41+
}
42+
43+
public void setId(long id) {
44+
this.id = id;
45+
}
46+
47+
public String getTitle() {
48+
return title;
49+
}
50+
51+
public void setTitle(String title) {
52+
this.title = title;
53+
}
54+
55+
public String getIsbn() {
56+
return isbn;
57+
}
58+
59+
public void setIsbn(String isbn) {
60+
this.isbn = isbn;
61+
}
62+
63+
public String getAuthor() {
64+
return author;
65+
}
66+
67+
public void setAuthor(String author) {
68+
this.author = author;
69+
}
70+
71+
//
72+
73+
@Override
74+
public int hashCode() {
75+
final int prime = 31;
76+
int result = 1;
77+
result = (prime * result) + ((author == null) ? 0 : author.hashCode());
78+
result = (prime * result) + (int) (id ^ (id >>> 32));
79+
result = (prime * result) + ((isbn == null) ? 0 : isbn.hashCode());
80+
result = (prime * result) + ((title == null) ? 0 : title.hashCode());
81+
return result;
82+
}
83+
84+
@Override
85+
public boolean equals(Object obj) {
86+
if (this == obj) {
87+
return true;
88+
}
89+
if (obj == null) {
90+
return false;
91+
}
92+
if (getClass() != obj.getClass()) {
93+
return false;
94+
}
95+
final Book other = (Book) obj;
96+
if (author == null) {
97+
if (other.author != null) {
98+
return false;
99+
}
100+
} else if (!author.equals(other.author)) {
101+
return false;
102+
}
103+
if (id != other.id) {
104+
return false;
105+
}
106+
if (isbn == null) {
107+
if (other.isbn != null) {
108+
return false;
109+
}
110+
} else if (!isbn.equals(other.isbn)) {
111+
return false;
112+
}
113+
if (title == null) {
114+
if (other.title != null) {
115+
return false;
116+
}
117+
} else if (!title.equals(other.title)) {
118+
return false;
119+
}
120+
return true;
121+
}
122+
123+
@Override
124+
public String toString() {
125+
final StringBuilder builder = new StringBuilder();
126+
builder.append("Book [id=")
127+
.append(id)
128+
.append(", title=")
129+
.append(title)
130+
.append(", isbn=")
131+
.append(isbn)
132+
.append(", author=")
133+
.append(author)
134+
.append("]");
135+
return builder.toString();
136+
}
137+
138+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
spring.application.name=spring-cloud-eureka-client
2+
server.port=0
3+
eureka.client.serviceUrl.defaultZone=${EUREKA_URI:http://localhost:8761/eureka}
4+
eureka.instance.preferIpAddress=true
5+
6+
spring.datasource.driver-class-name=org.h2.Driver
7+
spring.datasource.url=jdbc:h2:mem:cloud_rest;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
8+
spring.datasource.username=sa
9+
spring.datasource.password=
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.baeldung;
2+
3+
import org.junit.Test;
4+
import org.junit.runner.RunWith;
5+
import org.springframework.boot.test.context.SpringBootTest;
6+
import org.springframework.test.context.junit4.SpringRunner;
7+
8+
@RunWith(SpringRunner.class)
9+
@SpringBootTest
10+
public class SpringCloudRestClientApplicationTests {
11+
12+
@Test
13+
public void contextLoads() {
14+
}
15+
16+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
4+
### STS ###
5+
.apt_generated
6+
.classpath
7+
.factorypath
8+
.project
9+
.settings
10+
.springBeans
11+
12+
### IntelliJ IDEA ###
13+
.idea
14+
*.iws
15+
*.iml
16+
*.ipr
17+
18+
### NetBeans ###
19+
nbproject/private/
20+
build/
21+
nbbuild/
22+
dist/
23+
nbdist/
24+
.nb-gradle/

0 commit comments

Comments
 (0)